ListIconGadget Sort

Using Javascript from SpiderBasic
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

ListIconGadget Sort

Post by Dirk Geppert »

I use Peters ListIconGadgetEx() (https://github.com/spiderbytes/ListIconGadgetEx) - many thanks for that Peter! :D

There is a sorting function included that sorts the listitems numerically or case-sensitively by header click.

I have two questions about this:

1. How can I sort this in a non-case sensitive way?
2. In the demo, a pictogram is added to the header to indicate the sorting direction. Unfortunately, this pictogram is not visible in my coding. Where is this controlled?


This is the case sensitve sorting part:

Code: Select all

Procedure SortCallback(ListIconGadget, Column, Descending)
  
  Protected Counter
  Protected Line.s
  Protected Numeric
  
  ! var a = [];
  
  For Counter = 0 To CountGadgetItems(ListIconGadget) - 1
    
    ; CallDebugger
    
    Line = GetGadgetItemText(ListIconGadget, Counter)
    
    ! a.push(v_line.split(String.fromCharCode(10)));
    
  Next
  
  ! var column = []
  ! for (var c = 0; c <= a.length - 1; c++) {
  !   column.push(a[c][v_column]);
  ! }
  ! v_numeric = !column.some(isNaN);
  
  If Numeric
    If Descending
      ! a.sort(function(a, b) { return a[v_column] - b[v_column] });
    Else
      ! a.sort(function(a, b) { return b[v_column] - a[v_column] });
    EndIf
  Else
    If Descending
      ! a.sort(function(a, b) { if (a[v_column] == b[v_column]) { return 0; } else { return a[v_column] > b[v_column] ? -1 : 1; } });
    Else
      ! a.sort(function(a, b) { if (a[v_column] == b[v_column]) { return 0; } else { return a[v_column] < b[v_column] ? -1 : 1; } });
    EndIf
  EndIf
  
  ! for (var c = 0; c <= a.length - 1; c++) {
  !   spider_SetGadgetItemText(v_listicongadget, c, a[c].join(String.fromCharCode(10)));
  ! }
    
EndProcedure

I would have the idea to change the letters to capital letters before the comparison. Or is there a better way?

Code: Select all

    If Descending
      ! a.sort(function(a, b) { if (a[v_column].toUpperCase() == b[v_column].toUpperCase()) { return 0; } else { return a[v_column].toUpperCase() > b[v_column].toUpperCase() ? -1 : 1; } });
    Else
      ! a.sort(function(a, b) { if (a[v_column].toUpperCase() == b[v_column].toUpperCase()) { return 0; } else { return a[v_column].toUpperCase() < b[v_column].toUpperCase() ? -1 : 1; } });
    EndIf
kind regards

Dirk