Wijmo Sorting not working properly

Posted by: meghas on 15 May 2020, 6:39 am EST

  • Posted 15 May 2020, 6:39 am 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.
  • Replied 17 May 2020, 3:44 pm 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
  • Replied 17 May 2020, 7:26 pm 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
    1. 111111
    2.abcd
    3.122SS
    4.123-456
    so in this case how wijmo sorting will work?
  • Replied 18 May 2020, 4:19 pm 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
  • Replied 19 May 2020, 12: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..
  • Replied 19 May 2020, 6:24 pm 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
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels