Okay thankyou...this (
viewtopic.php?p=20135#p20135) was quiet helpful*. So here is my solution:
Code: Select all
@REQUIRE "RapaGUI"
@FILE 1, "sorttest.xml"
moai.CreateApp(FileToString("sorttest.xml"))
t = {"11.11.2025", "11.11.2027", "1.1.2028", "3.3.1972"}
f = {"Birkenfeld", "Meier", "Anton", "Zappel"}
Function p_CompareFunc(e1, e2)
/******* split up Datestring and rearrange to YYYYMMDD ****/
If tv = 0 ;a date based column
Local d1$, m1$, y1$ = PatternFindStrShort(e1, "(%d+).(%d+).(%d+)")
Local d2$, m2$, y2$ = PatternFindStrShort(e2, "(%d+).(%d+).(%d+)")
Local v1, v2 = Val(FormatStr("%s%02s%02s", y1$, m1$, d1$)), Val(FormatStr("%s%02s%02s", y2$, m2$, d2$))
If v1 < v2 Then Return(-1)
If v1 > v2 Then Return(1)
EndIf
If tv = 1 ;plain alphabetical column
If e1 < e2 Then Return(-1)
If e1 > e2 Then Return(1)
EndIf
Return(0)
EndFunction
InstallEventHandler({RapaGUI = Function(msg)
If msg.attribute = "SortColumn"
tv = msg.triggervalue ;holds the column number you pressed...
EndIf
If msg.attribute = "CompareItems" Then Return(p_CompareFunc(msg.entry1, msg.entry2))
If msg.attribute = "Pressed"
If msg.ID = "btn_datum"
DebugPrint("Datum sort")
ElseIf msg.ID = "btn_name"
DebugPrint("Name sort")
EndIf
EndIf
EndFunction})
For Local k = 0 To ListItems(t) - 1
moai.DoMethod("lv", "insert", "bottom", t[k], f[k])
Next
Repeat
WaitEvent
Forever
This one is the important bit (for me) as it calls the procedure "p_compareFunc()", every time two items have to be compared (the longer the list,the more often this functions will be called, I guess):
Code: Select all
If msg.attribute = "CompareItems" Then Return(p_CompareFunc(msg.entry1, msg.entry2))
Inside the mentioned function I react differently, according wether the date or the name column was clicked. Here is the xml file as well:
Code: Select all
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app" useicons="true">
<window title="Messages und Listen">
<vgroup>
<hgroup>
<button id="btn_datum">Datum</button>
<button id="btn_name">Name</button>
</hgroup>
<listview id="lv" notify="active; CompareItems;SortColumn">
<column title="Spalte0" sortable="true" editable="true"></column>
<column title="Spalte1" sortable="true" editable="true"></column>
</listview>
</vgroup>
</window>
</application>
*already read it yesterday...but had to dig a bit deeper to understand.