AW: Sorting headed lists

Rudolf Bargholz rudolf at bargholz.ch
Thu Jul 10 06:59:40 EDT 2014


Hi Jean Marc,

Just to make mention this explicitly:

The code can be used behind any headed list using a local variable. This is how we have it in most of our code. With a local variable the state of the previous clicked column cannot be saved (ok, I could store it in the $desc of the instantiated local variable, but I haven't gotten around to do this). In the second example the sorting object for the list is stored as an instance variable in the window, and can thus save the state of previously clicked columns.

Regards

Rudolf

-----Ursprüngliche Nachricht-----
Von: omnisdev-en-bounces at lists.omnis-dev.com [mailto:omnisdev-en-bounces at lists.omnis-dev.com] Im Auftrag von Rudolf Bargholz
Gesendet: Donnerstag, 10. Juli 2014 12:52
An: OmnisDev List - English
Betreff: AW: Sorting headed lists

Hi Jean Marc,

"Will it be relevant if a sort have been previously set on another column?"

The depends. For the first sort the code currently takes the first and last values, and will by default sort in the opposite direction when comparing the first and last values. After the first sort the sort order will automatically revert.

Sent the library directly.

Regards

Rudolf

-----Ursprüngliche Nachricht-----
Von: omnisdev-en-bounces at lists.omnis-dev.com [mailto:omnisdev-en-bounces at lists.omnis-dev.com] Im Auftrag von Jean Marc Azerad
Gesendet: Donnerstag, 10. Juli 2014 12:46
An: OmnisDev List - English
Betreff: Re: Sorting headed lists


Hi Rudolf

Thanks for your help, I love the use of eval() here.
Weird use of kfetchall too
And I've never thought about testing the values of first and last value to decide the way to sort. Not sure I fully get this... (Will it be relevant if a sort have been previously set on another column? First and last may be ordered, but not those in between...) Please, do send me your demo lib, I'll be really glad to explore this

Thank you again

JM



Le 10 juil. 2014 à 12:36, Rudolf Bargholz <rudolf at bargholz.ch> a écrit :

> Hi,
> 
> If anyone is interested I have extracted a demo library based on the code below. The code shows the following:
> 
> 1) Generic sorting, where all columns are taken to be a string. All you need to pass to the object is the pColumnNumber.
> 2) If one sorts a columns first descending, and clicks on the column 
> again, the ordering will be ascending
> 3) The current line is preserved after sort, in other words the values that were current before sorting will remain current after sorting.
> 4) If I click on a column, then press CTRL and press on another column header in the headed list, the second column will be the second sort criterion. Up to 9 sort fields can be set this way.
> 5) If in the example (4) I click on the same second column with CTRL a second time, then the ordering of the second column will be reversed.
> 
> Studio 4.3.0 non-unicode
> 
> If you would like the code, just drop me a mail and I will respond with the library.
> 
> Regards
> 
> Rudolf Bargholz
> 
> -----Ursprüngliche Nachricht-----
> Von: omnisdev-en-bounces at lists.omnis-dev.com
> [mailto:omnisdev-en-bounces at lists.omnis-dev.com] Im Auftrag von Rudolf 
> Bargholz
> Gesendet: Donnerstag, 10. Juli 2014 09:27
> An: OmnisDev List - English
> Betreff: AW: Sorting headed lists
> 
> Hi Jean Marc,
> 
> The basis for a generalized solution could be the fact that the sort parameter of $sort can take a calculation, not just a single column. And the $calculation can easily be split up to find the portion of the $calculation that is relevant for the header you clicked on. Below a working solution that you ought to be able to paste behind an existing headed list.
> 
> 
> On evHeaderClick
> 
> Calculate lCalc as $cfield.$calculation Calculate lCalc as
> mid(lCalc,5,kFetchAll) Calculate lCalc as mid(lCalc,1,len(lCalc)-1)
> 
> Calculate lCalc as replaceall(lCalc,",con(9),",",kTab,")
> 
> Calculate lPos as 1
> 
> Repeat
> Do lStringObj.$strtok(",kTab,",lCalc,lCut)
> Calculate lPos as lPos+1
> Until lPos>pColumnNumber
> 
> Calculate lCurrentLine as $cfield.$line Calculate $cfield.$line as 1 
> Calculate lValueFirstLine as eval(lCut) Calculate $cfield.$line as 
> $cfield.$linecount Calculate lValueLastLine as eval(lCut) Calculate 
> $cfield.$line as lCurrentLine
> 
> If lValueFirstLine<lValueLastLine
> Do $cfield.$sort(eval(lCut),kTrue)
> Else
> Do $cfield.$sort(eval(lCut),kFalse)
> End If
> Do $cinst.$redraw()
> 
> 
> Here the code for our Omnis code implementation of strtok. We found out after months of searching that when Studio was running as a service the internal strtok() function of Omnis would intermittently crash Omnis. And the code implementation allows not just a one string tokenization, but your SearchString can have a length > 1. The lStringObj in the above code is an object class that has a $strtok method.
> 
> $strtok:
> pSearchString: pSearchString
> pfBaseVar: Field reference
> pfReturnVar: Field reference
> 
> 
> Optimize method
> If len(pSearchString)=0
> Calculate pfReturnVar as pfBaseVar
> Calculate pfBaseVar as ''
> 
> Else
> Calculate pos as pos(pSearchString,pfBaseVar)
> 
> If pos=0
> Calculate pfReturnVar as pfBaseVar
> Calculate pfBaseVar as ''
> 
> Else
> Calculate lenSearchString as len(pSearchString) Calculate pfReturnVar 
> as mid(pfBaseVar,1,pos-1) Calculate pfBaseVar as
> mid(pfBaseVar,pos+lenSearchString,kFetchAll)
> 
> End If
> 
> End If
> 
> Quit method kTrue
> 
> Regards
> 
> Rudolf Bargholz
> 
> -----Ursprüngliche Nachricht-----
> Von: omnisdev-en-bounces at lists.omnis-dev.com
> [mailto:omnisdev-en-bounces at lists.omnis-dev.com] Im Auftrag von Jean 
> Marc Azerad
> Gesendet: Mittwoch, 9. Juli 2014 19:56
> An: OmnisDev List - English
> Betreff: Sorting headed lists
> 
> Hi $all,
> 
> It's late and my brain is somewhere ... but can't find it... Maybe its obvious, maybe not...
> 
> When clicking on the header, I need to sort a headed list depending on the CONTENT of the displayed column, not the underlying list variable...
> The content is dynamically calculated line per line and quite complex (include pick() con()..., so choosing fields in the list is just not possible.
> Any clue anyone?
> 
> Thanks!
> 
> JM_____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com 
> _____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com 
> _____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com

_____________________________________________________________
Manage your list subscriptions at http://lists.omnis-dev.com _____________________________________________________________
Manage your list subscriptions at http://lists.omnis-dev.com



More information about the omnisdev-en mailing list