Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Nick Armitage on Nov 09, 2007 02:21
open dhtmlx forum
dhtmlxGrid - Case Insensitive Sorting

Is there any way to make the alphabetic sorting of a standard dhtmlxGrid control case insensitive?
I couldn't work out why when I clicked on the column header that something like N came before a!!
I realised it is because "N" is in upper case and this comes before a lower case "a".

I don't really want to convert the column data to lower case to make this work but that is obviously one solution.
So was wondering if there was an option somewhere to make the sorting case insensitive.

If I have to write a custom sort function, can anyone give me a code snippet to do this.
Answer posted on Nov 09, 2007 05:47
By default sorting is case sensitive, you can change such behavior by using custom sorting.

grid.setCustomSorting(function(a,b,order){
    a=(a||"").toString().toLowerCase();
    b=(b||"").toString().toLowerCase();

    if (order) return (a>b?1:-1);
    else return (a<b?1:-1);
  
},INDEX);

where INDEX - index of column for which custom sorting must be used