Re: PureLVSORT library : sorting ListIconGadgets (and more)
Posted: Fri Dec 03, 2010 7:41 pm

http://www.purebasic.com
https://www.purebasic.fr/english/
i have considered this method but the problem is how to click the column header if the column i want to sort is hidden.Michael Vogel wrote:Not sure, if implementing such things would slow down sorting (maybe someone needs rational numbers etc.)...
...I would think about adding a hidden column containing the unretouched values -- this column could be sorted easily
The user callback is quite easy to use.liam wrote:then i tried using PureLVSORT_DefineUserCallback but i encountered another roadblock because i couldn't make it work with predefined procedures.
id be grateful, if you could provide a simple working example how to do this.
Code: Select all
;/ USER CALLBACK
Procedure.l MySortingCallback(ListIconNumber.l, ListIconColumn.l, Item1.s, Item2.s)
Protected ReturnValue.l
Debug Str(ListIconNumber) + ":" + Str(ListIconColumn) + "->" + Item1 + ":" + Item2
;
; Compare Item1 And Item2 ..
; Return 1 If Item1 > Item2
; Return -1 If Item1 < Item2
; Return 0 If Item1 = Item2
;
If Item1 > Item2
ReturnValue = 1
ElseIf Item1 < Item2
ReturnValue = -1
Else
ReturnValue = 0
EndIf
ProcedureReturn ReturnValue
EndProcedure
;/ Example
#Window_0 = 0
#ListIcon_0 = 0
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 602, 302, "PureLVSORT User Callback", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
ListIconGadget(#ListIcon_0, 5, 5, 590, 285, "UserCallback", 110)
AddGadgetColumn(#ListIcon_0, 1, "DateDDMMYYYYHHMMSS", 130)
AddGadgetColumn(#ListIcon_0, 2, "DateDDMMYYHHMM", 130)
AddGadgetColumn(#ListIcon_0, 3, "DateDDMMYYYY", 120)
AddGadgetColumn(#ListIcon_0, 4, "DateMMDDYYYY", 120)
AddGadgetColumn(#ListIcon_0, 5, "FileSize", 120)
AddGadgetColumn(#ListIcon_0, 6, "UserCallback", 120)
AddGadgetItem(#ListIcon_0, -1, "aseza" + Chr(10) + "12/05/2001 06:41:30" + Chr(10) + "19/07/66 06:41" + Chr(10) + "31/12/2004" + Chr(10) + "12/31/2004" + Chr(10) + "15.02 MB" + Chr(10) + "0")
AddGadgetItem(#ListIcon_0, -1, "zssdd" + Chr(10) + "05/07/2004 09:21:30" + Chr(10) + "12/05/01 07:50" + Chr(10) + "11/12/2004" + Chr(10) + "12/11/2004" + Chr(10) + "65 B" + Chr(10) + "1")
AddGadgetItem(#ListIcon_0, -1, "aeeed" + Chr(10) + "19/11/2003 07:18:31" + Chr(10) + "13/08/03 06:41" + Chr(10) + "21/01/2003" + Chr(10) + "01/21/2003" + Chr(10) + "5.98 GB" + Chr(10) + "3")
AddGadgetItem(#ListIcon_0, -1, "udsdd" + Chr(10) + "19/11/2003 06:21:30" + Chr(10) + "12/05/01 06:41" + Chr(10) + "10/06/2001" + Chr(10) + "06/10/2001" + Chr(10) + "100 KB" + Chr(10) + "A")
AddGadgetItem(#ListIcon_0, -1, "cdgdd" + Chr(10) + "19/11/2003 16:21:30" + Chr(10) + "12/05/01 06:41" + Chr(10) + "10/08/2001" + Chr(10) + "16/11/2001" + Chr(10) + "800 KB" + Chr(10) + "9")
AddGadgetItem(#ListIcon_0, -1, "adsdg" + Chr(10) + "19/11/2003 06:21:31" + Chr(10) + "12/05/01 06:41" + Chr(10) + "10/06/2004" + Chr(10) + "06/10/2004" + Chr(10) + "101 KB" + Chr(10) + "z")
AddGadgetItem(#ListIcon_0, -1, "azsdd" + Chr(10) + "19/11/2003 06:21:30" + Chr(10) + "12/05/01 06:41" + Chr(10) + "10/04/2001" + Chr(10) + "07/08/2004" + Chr(10) + "1000 B" + Chr(10) + "A")
EndIf
EndProcedure
Open_Window_0()
; ListIcon Sort Setup
If PureLVSORT_SelectGadgetToSort(#ListIcon_0, #PureLVSORT_ShowClickedHeader_IconLeft) = #PureLVSORT_Ok
PureLVSORT_DefineUserCallback(@MySortingCallback())
PureLVSORT_SetColumnType(#ListIcon_0, 0, #PureLVSORT_UserCallback)
PureLVSORT_SetColumnType(#ListIcon_0, 1, #PureLVSORT_DateDDMMYYYYHHMMSS)
PureLVSORT_SetColumnType(#ListIcon_0, 2, #PureLVSORT_DateDDMMYYHHMM)
PureLVSORT_SetColumnType(#ListIcon_0, 3, #PureLVSORT_DateDDMMYYYY)
PureLVSORT_SetColumnType(#ListIcon_0, 4, #PureLVSORT_DateMMDDYYYY)
PureLVSORT_SetColumnType(#ListIcon_0, 5, #PureLVSORT_FileSize)
PureLVSORT_SetColumnType(#ListIcon_0, 6, #PureLVSORT_UserCallback)
PureLVSORT_SortListIconNow(#ListIcon_0, 1, -1)
EndIf
;
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
Code: Select all
;/ USER CALLBACK
Procedure.l MySortingCallback(ListIconNumber.l, ListIconColumn.l, Item1.s, Item2.s)
Protected ReturnValue.l
Debug Str(ListIconNumber) + ":" + Str(ListIconColumn) + "->" + Item1 + ":" + Item2
;
; Compare Item1 And Item2 ..
; Return 1 If Item1 > Item2
; Return -1 If Item1 < Item2
; Return 0 If Item1 = Item2
;
If Item1 > Item2
ReturnValue = 1
ElseIf Item1 < Item2
ReturnValue = -1
Else
ReturnValue = 0
EndIf
ProcedureReturn ReturnValue
EndProcedure
;/ Example
#Window_0 = 0
#ListIcon_0 = 0
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 602, 302, "PureLVSORT User Callback", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
ListIconGadget(#ListIcon_0, 5, 5, 590, 285, "UserCallback", 110)
AddGadgetColumn(#ListIcon_0, 1, "UserCallback", 120)
AddGadgetItem(#ListIcon_0, -1, "$36.00" + Chr(10) + "36.00")
AddGadgetItem(#ListIcon_0, -1, "$324.00" + Chr(10) + "324.00")
AddGadgetItem(#ListIcon_0, -1, "$324,432.45" + Chr(10) + "324,432.45")
AddGadgetItem(#ListIcon_0, -1, "$2,561.45" + Chr(10) + "2561.45")
EndIf
EndProcedure
Open_Window_0()
; ListIcon Sort Setup
If PureLVSORT_SelectGadgetToSort(#ListIcon_0, #PureLVSORT_ShowClickedHeader_IconLeft) = #PureLVSORT_Ok
PureLVSORT_DefineUserCallback(@MySortingCallback())
PureLVSORT_SetColumnType(#ListIcon_0, 0, #PureLVSORT_UserCallback)
PureLVSORT_SetColumnType(#ListIcon_0, 1, #PureLVSORT_NoSorting)
EndIf
;
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
With PureLVSORT, the sorting is done according to the column you clicked on.liam wrote:lets say i have this listicon data below. how do i sort the rows according to the 2nd column by clicking the 1st column header? im still learning PB programming so please bear with me![]()
Code: Select all
;/ USER CALLBACK
Procedure.l MySortingCallback(ListIconNumber.l, ListIconColumn.l, Item1.s, Item2.s)
Protected ReturnValue.l
Protected Item1D.d, Item2D.d
;
; Quick and dirty transforming Currency to DOUBLE
Item1 = RemoveString(Item1, "$")
Item1 = RemoveString(Item1, ",")
Item1D = ValD(Item1)
Item2 = RemoveString(Item2, "$")
Item2 = RemoveString(Item2, ",")
Item2D = ValD(Item2)
;
If Item1D > Item2D
ReturnValue = 1
ElseIf Item1D < Item2D
ReturnValue = -1
Else
ReturnValue = 0
EndIf
ProcedureReturn ReturnValue
EndProcedure
;/ Example
#Window_0 = 0
#ListIcon_0 = 0
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 602, 302, "PureLVSORT User Callback", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
ListIconGadget(#ListIcon_0, 5, 5, 590, 285, "UserCallback", 110)
AddGadgetColumn(#ListIcon_0, 1, "No sorting", 120)
AddGadgetItem(#ListIcon_0, -1, "$36.00" + Chr(10) + "36.00")
AddGadgetItem(#ListIcon_0, -1, "$324.00" + Chr(10) + "324.00")
AddGadgetItem(#ListIcon_0, -1, "$324,432.45" + Chr(10) + "324,432.45")
AddGadgetItem(#ListIcon_0, -1, "$2,561.45" + Chr(10) + "2561.45")
EndIf
EndProcedure
Open_Window_0()
; ListIcon Sort Setup
If PureLVSORT_SelectGadgetToSort(#ListIcon_0, #PureLVSORT_ShowClickedHeader_IconLeft) = #PureLVSORT_Ok
PureLVSORT_DefineUserCallback(@MySortingCallback())
PureLVSORT_SetColumnType(#ListIcon_0, 0, #PureLVSORT_UserCallback)
PureLVSORT_SetColumnType(#ListIcon_0, 1, #PureLVSORT_NoSorting)
EndIf
;
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
With PureLVSORT, the sorting is done according to the column you clicked on.gnozal wrote:liam wrote:lets say i have this listicon data below. how do i sort the rows according to the 2nd column by clicking the 1st column header? im still learning PB programming so please bear with me![]()
Did you try the code I posted ? It shows how to sort a column by transforming a format ('currency') to another (double float).liam wrote:...im not sure though how to implement usercallbacks to address my problem.
so if you could implement #PureLVSORT_Currency format, it could save a lot of people like me a lot of hair
i tried the code you posted, actually its identical to the sample code in PureLVSORT lib's documentation. all i see are strings, dates, filesizes but no currency-to-float conversions. i even posted a reply with your sample code and my sample currency data but it didn't work.Did you try the code I posted ? It shows how to sort a column by transforming a format ('currency') to another (double float).
I mean this code I posted not one hour ago :liam wrote:i tried the code you posted, actually its identical to the sample code in PureLVSORT lib's documentation. all i see are strings, dates, filesizes but no currency-to-float conversions. i even posted a reply with your sample code and my sample currency data but it didn't work.
Code: Select all
;/ USER CALLBACK
Procedure.l MySortingCallback(ListIconNumber.l, ListIconColumn.l, Item1.s, Item2.s)
Protected ReturnValue.l
Protected Item1D.d, Item2D.d
;
; Quick and dirty transforming Currency to DOUBLE
Item1 = RemoveString(Item1, "$")
Item1 = RemoveString(Item1, ",")
Item1D = ValD(Item1)
Item2 = RemoveString(Item2, "$")
Item2 = RemoveString(Item2, ",")
Item2D = ValD(Item2)
;
If Item1D > Item2D
ReturnValue = 1
ElseIf Item1D < Item2D
ReturnValue = -1
Else
ReturnValue = 0
EndIf
ProcedureReturn ReturnValue
EndProcedure
;/ Example
#Window_0 = 0
#ListIcon_0 = 0
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 602, 302, "PureLVSORT User Callback", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
ListIconGadget(#ListIcon_0, 5, 5, 590, 285, "UserCallback", 110)
AddGadgetColumn(#ListIcon_0, 1, "No sorting", 120)
AddGadgetItem(#ListIcon_0, -1, "$36.00" + Chr(10) + "36.00")
AddGadgetItem(#ListIcon_0, -1, "$324.00" + Chr(10) + "324.00")
AddGadgetItem(#ListIcon_0, -1, "$324,432.45" + Chr(10) + "324,432.45")
AddGadgetItem(#ListIcon_0, -1, "$2,561.45" + Chr(10) + "2561.45")
EndIf
EndProcedure
Open_Window_0()
; ListIcon Sort Setup
If PureLVSORT_SelectGadgetToSort(#ListIcon_0, #PureLVSORT_ShowClickedHeader_IconLeft) = #PureLVSORT_Ok
PureLVSORT_DefineUserCallback(@MySortingCallback())
PureLVSORT_SetColumnType(#ListIcon_0, 0, #PureLVSORT_UserCallback)
PureLVSORT_SetColumnType(#ListIcon_0, 1, #PureLVSORT_NoSorting)
EndIf
;
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
It looks like your are using the wrong library version.rule wrote:I've tried to run one of your example programs PureLVSORT_TEST_2.pb and I get a Polink error "Unresolved external symbol '_PB_Findstring2.'