Sorting a String column gives wrong results when numbers are included

2 posts, 1 answers
  1. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 20 May 2015 Link to this post


    One of the columns is an ID of a record. Id has a certain format something like: XXXX-XXX-1 etc.

     When sorting on this column values show as:







    Is there a way to properly sort such that -10 appears after?



  2. Answer
    Plamen Lazarov
    Plamen Lazarov avatar
    135 posts

    Posted 21 May 2015 Link to this post

    Hello Bilal,

    The reason for this behavior is because by default JavaScript sort() method sorts elements alphabetically. I would offer to take a look at  Array.prototype.sort() article that explains the same.

    I would suggest to take a look at resource which gives the opportunity to specify custom sorting function. In order to sort numerically it would be necessary to implement a custom sorting logic. 

    Let us know if that helps.

    Plamen Lazarov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top