Posted 15 May 2020, 3:39 pm EST
Wijmo Sorting not working properly.
I have a column with numbers.
It has data like 0011910, 1011653,103072 but the sorting is not working correctly.
Forums Home / Wijmo / General Discussion
Posted by: meghas on 15 May 2020, 3:39 pm EST
Posted 15 May 2020, 3:39 pm EST
Wijmo Sorting not working properly.
I have a column with numbers.
It has data like 0011910, 1011653,103072 but the sorting is not working correctly.
Posted 18 May 2020, 12:44 am EST
Hi Megha,
It seems that you are storing the data as string because numbers like 0011910 cannot be stored as numbers as the leading zeros will be removed. You will need to convert these values from string to number.
But, if you cannot change these values into numbers, you can also use the sortConverter property of CollectionView class to convert them in to integers only while sorting.
https://www.grapecity.com/wijmo/api/classes/wijmo.collectionview.html#sortconverter
grid.collectionView.sortConverter = function(sd, item, value) {
if(sd.property === '**your column binding**') {
return +value; // convert to number
}
return value;
}
Regards,
Ashwin
Posted 18 May 2020, 4:26 am EST
Hi Ashwin, thank you, this solved my problem.
But I don’t understand how wijmo sorting works if any column has multiple type of data.
for eg
If I have a column ProductSSN and it can have value like
Posted 19 May 2020, 1:19 am EST
Hi Megha,
The sorting of the column is based on its dataType. In this case, most probably the dataType will be string. So, this column will be sorted in the string manner. After sorting, the values will be displayed as:
111111
122SS
123-456
abcd
I hope this clears your doubts.
~regards
Posted 19 May 2020, 9:52 am EST
Thank you Ashwin .
According to my understanding if sorting is according to data type and as in this mix type of content
11111
anbs
12-444
001113
I can not convert 001113 to number with sort convertor because, in this, a comparison will be between string and number which will not work correctly with mix type of data type.
I didn’t find any way to handle this…
Posted 20 May 2020, 3:24 am EST
Hi Megha,
I provided the sortConverter solution because I thought that your column only contained numerical values. If you column contains mix type like strings and numbers, then I would not suggest you sortConverter and let the grid handle the sorting. In this case, the grid will sort the data on the string basis as I said earlier which is the same behavior as excel.
~regards