AW: Sorting headed lists

Rudolf Bargholz rudolf at bargholz.ch
Thu Jul 10 06:36:02 EDT 2014


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



More information about the omnisdev-en mailing list