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

    Hi,

    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:

    XXXX-XXX-1

    XXXX-XXX-10

    XXXX-XXX-2

    XXXX-XXX-3

    ...

     

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

     

    Thanks

  2. Answer
    Plamen Lazarov
    Admin
    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 columns.sortable.compare 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.

    Regards,
    Plamen Lazarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top