This is a migrated thread and some comments may be shown as answers.

Sorting a String column gives wrong results when numbers are included

1 Answer 358 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 20 May 2015, 06:27 AM

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

1 Answer, 1 is accepted

Sort by
0
Accepted
Plamen Lazarov
Telerik team
answered on 21 May 2015, 03:56 PM

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!
 
Tags
Grid
Asked by
Bilal
Top achievements
Rank 2
Answers by
Plamen Lazarov
Telerik team
Share this question
or