plouf wrote: ↑Tue Jan 02, 2024 2:54 pm
airsoftsoftwair wrote: ↑Tue Jan 02, 2024 12:13 pm
plouf wrote: ↑Mon Jan 01, 2024 11:04 pm
does this change listview logic from "text" to "number" ? and if yes what else can understand ? date ? currency?
It can understand everything you need. Your callback simply tells the listview how to sort the entries. This allows you to impose any sort logic you want on the listview. Numbers, dates, currencies, whatever.
i can not understand how can this so "smart"
i try with your example the following
Code: Select all
t = {"21/12/2020","4/5/2021","30/01/1651","12/12/1900"}
no matter if p_CmpFunc return -1 0 or 1 , date is not correct. do i miss something or is just numbers<>characters
The p_CmpFunc just gets two values and returns -1, 0, or 1 after it has decided in which order these two values should be. It's up to your own code how the order should be defined.
The previous example was only to convert numerical strings to numbers and compare them. Now when you have string data that has slashes in it, Val("21/12/2020") just gives 21 as the result. So you're comparing the data by the day numbers, not with the whole date.
Here's an example logic to compare dates in the format you gave (haven't thought if it's optimal by speed, but an example anyway):
Code: Select all
Function p_CmpFuncDate(e1, e2)
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)
Return(0)
EndFunction
It picks day, month, and year from the input data, and converts them to numeric YearMonthDay format with padding zeroes in day and month. In this form it's easy to compare them again as numbers.
As told, you can write any kind sorting algorithms in this way, everything is possible

But of course you have to modify the sorting algorithm to match your data.
I myself have written custom sorting algorithms in RNOArchive and RNOTunes, and probably somewhere else too. I have usually used Hollywood's own date format for dates, and then the compare function can just use
CompareDates() function to determine the order. I also have made some generic sorting functions that operate in different ways according the column that has been clicked and have reversed sorting if clicking the same column again.