Can listbrowser.gadget sort COL1&COL2?

11 posts / 0 new
Last post
jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2013-05-30 00:53
Can listbrowser.gadget sort COL1&COL2?
Hi, want to know if lb gadget can sort COLUMN1 and at same time COLUMN2 (dependig on COLUMN1). I mean, having COL1=month and COL2=day in a lb, sort the list first by month (COL1) and then by day (COL2):
Month | Day
------+------
  1   |  2
  1   |  8
  2   | 10
  2   | 20
..
Or do I have to "cook" the code for such purpose? TIA
trixie
trixie's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-02-03 13:58
@jabirulo What you are
@jabirulo What you are requesting would require the listbrowser to rehash the physical pairing of values in the individual nodes - not just rearrange node order in the list. I don't think that is supported.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
gazelle
gazelle's picture
Offline
Last seen: 6 years 2 months ago
Joined: 2011-04-13 12:52
@jabirulo if I read the
@jabirulo if I read the autodocs correctly the listnodes are always sorted first by their priority. If you set the LBNA_Priority of the listnodes to the month and sort by the day column should do what you want.
jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2013-05-30 00:53
Hi, just tried
Hi, just tried 'LBNA_Priority,5' and don't seems to change anything (or possible that I'm doing it wrong) it just sorts by the day (DD) column, so maybe lb_gadget can't sort by itself "DD col inside MM col":
  1. ..
  2. struct List listbrowser_list;
  3. ..
  4. struct ColumnInfo *columninfo;
  5. columninfo = IListBrowser->AllocLBColumnInfo(TOTALCOLUMNS,
  6. LBCIA_Column,0, LBCIA_Title,"MM",
  7. LBCIA_AutoSort,TRUE, LBCIA_Flags,CIF_SORTABLE,
  8. LBCIA_Column,1, LBCIA_Title," DD",
  9. LBCIA_AutoSort,TRUE, LBCIA_Flags,CIF_SORTABLE,
  10. LBCIA_Column,2, LBCIA_Title," MyDay",
  11. TAG_DONE);
  12. ..
  13. LAYOUT_AddChild, OBJ(GID_LISTBROWSER) = IIntuition->NewObject(NULL, "listbrowser.gadget",
  14. GA_ID, GID_LISTBROWSER,
  15. GA_RelVerify, TRUE,
  16. LISTBROWSER_SortColumn, 1,
  17. LISTBROWSER_AutoFit, TRUE,
  18. LISTBROWSER_Labels, &listbrowser_list,
  19. LISTBROWSER_ColumnInfo, columninfo,
  20. LISTBROWSER_ColumnTitles, TRUE,
  21. LISTBROWSER_ShowSelected, TRUE,
  22. LISTBROWSER_Selected, -1,
  23. LISTBROWSER_MinVisible, 10,
  24. LISTBROWSER_Striping, LBS_ROWS,
  25. //LISTBROWSER_HorizSeparators, TRUE,
  26. LISTBROWSER_HorizontalProp, TRUE,
  27. //LISTBROWSER_AutoVirtualWidth, TRUE,
  28. TAG_DONE),
  29. ..
  30. int32 month, day;
  31. STRPTR text;
  32. struct Node *n;
  33. ..
  34. if( (n = IListBrowser->AllocListBrowserNode(TOTALCOLUMNS,
  35. LBNA_Priority,5, LBNA_Column,0, LBNCA_CopyInteger,TRUE, LBNCA_Integer,&month,
  36. LBNA_Column,1, LBNCA_CopyInteger,TRUE, LBNCA_Integer,&day,
  37. LBNA_Column,2, LBNCA_CopyText,TRUE, LBNCA_Text,text,
  38. TAG_DONE)) )
  39. {
  40. IExec->AddTail(&listbrowser_list, n);
  41. }
  42. ..
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
gazelle
gazelle's picture
Offline
Last seen: 6 years 2 months ago
Joined: 2011-04-13 12:52
@jabirulo Setting the
@jabirulo Setting the priority to 5 will not change anything because it's the same for all nodes. Try "LBNA_Priority,month" instead and only sort the day column.
jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2013-05-30 00:53
GREAT!!! Changing to: if( (n
GREAT!!! Changing to: if( (n = IListBrowser->AllocListBrowserNode(TOTALCOLUMNS, LBNA_Priority,-month,.. makes sort month and DAY!!! Had to put '-' (negativ), 'cos sorting month were from 12..1 in listbrowser, but will try to use/add LBCIA_SortDirection if it makes a difference.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
broadblues
broadblues's picture
Offline
Last seen: 2 years 9 months ago
Joined: 2012-05-02 21:48
The correct way to do this is
The correct way to do this is to provide a compare hook when setting up your LBColumnInfo. LBCIA_CompareHook (struct Hook *) The sort comparison hook to use on the column. This is the exact same hook used by the LBM_SORT method. See the LBM_SORT method documentation for more information. This hook will only be used if the column is marked sortable (see LBCIA_Sortable tag). Defaults to NULL (default LBM_SORT comparison). The Compare function can then compare nodes by whatever criteria you want.
jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2013-05-30 00:53
THX, will try to do it the
THX, will try to do it the correct_way_TM ASAP.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2013-05-30 00:53
Ok, just "playing" a bit with
Ok, just "playing" a bit with 'LBCIA_CompareHook,compare_hook,' just get to sort MM (month) column, but days still not sorted.
  1. struct Hook *compare_hook = IExec->AllocSysObjectTags(ASOT_HOOK,
  2. ASOHOOK_Entry, compare_func,
  3. TAG_DONE);
  4. ..
  5. int32 compare_func(struct Hook *hook, APTR obj, struct LBSortMsg *msg)
  6. {
  7. blah blah
  8. }..
Is there someway to get current node 'compare_func()' is comparing, so I can get DD (day) and (re)sort in case Day_A < Day_B? All inside this same compare_func(). Or do I must to (re)sort DD "again" with another (almost identic) 'compare_func()'. TIA
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
broadblues
broadblues's picture
Offline
Last seen: 2 years 9 months ago
Joined: 2012-05-02 21:48
Without knowing what "blah,
Without knowing what "blah, Blah" is it's hard to comment in definete detail, but for any given row you must surely be about to determine the month and day info? You will need the userdata field of you node to point to some structure that holds the month and day info. Presumably whichever structure you created the row from in the first place. Or perhaps you could set it to the datestamp of the entire row, depends a lot on the structure of your application.
jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2013-05-30 00:53
As I'm just testing
As I'm just testing compare_func() hook is just now as simple as this (clone of LBM_SORT mode aprox.):
  1. int32 compare_func(struct Hook *hook, APTR obj, struct LBSortMsg *msg)
  2. {
  3. int32 result;
  4.  
  5. if(msg->lbsm_TypeA == 2 && msg->lbsm_TypeB == 2)
  6. {
  7. int32 AA = msg->lbsm_DataA.Integer;
  8. int32 BB = msg->lbsm_DataB.Integer;
  9. result = AA - BB;
  10. if(result == 0) // AA = BB
  11. {
  12. IDOS->Printf("%2ld = %2ld (0)\n",AA,BB);
  13. return 0;
  14. }
  15. else
  16. if(result > 0) // AA > BB
  17. {
  18. IDOS->Printf("%2ld > %2ld (1)\n",AA,BB);
  19. return 1;
  20. }
  21. else // AA < BB
  22. {
  23. IDOS->Printf("%2ld < %2ld (-1)\n",AA,BB);
  24. return -1;
  25. }
  26. IDOS->Printf("????\n");
  27. }
  28. return 0;
  29. }
Ok, thx. I gueesed I have to use UserData field, maybe filled with the node or just the DD, so I can get the DD field and then re-sort again if needed. THX
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Log in or register to post comments