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

Retaining leading zeros in a column

3 Answers 673 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Khushali
Top achievements
Rank 1
Khushali asked on 09 Apr 2012, 07:06 AM
Hi,

I have a kendo grid and one of the column is of type string. From server, i get data something like this: "000545". Now, before creating the grid, i am changing the datatype to number(done on client side). And then create the grid. While changing such data to int, i lose the leading zeros. And i want it to be of type number, as i want the sorting and filtering on that column. There is no way, i can modify the data on server-side as it comes from third party. Thats why, i am changing the datatype also on client side. Is there any way,that i can retain the leading zeros?

Regards,
Khushali

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 09 Apr 2012, 10:06 AM
Hello Khushali,

I suggest to add the leading zeros via column template, thus way will allow you to display the zeros and use the filtering and sorting functionality. For example: http://jsfiddle.net/valchev/vTsGY/ 

Please note that in the example I hard coded the number of zeros. It is possible to implement your logic how to prepend them through JavaScript.

Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Khushali
Top achievements
Rank 1
answered on 09 Apr 2012, 12:36 PM
Hi Alexander,

Column template can be used if i know the exact length of the string. But, if i dont know what length that string will have, i can't prepend the zeroes. Is there any way, that i can display one column(having string),and do sorting on other column(having number) which is hidden?

Regards,
Khushali
0
Alexander Valchev
Telerik team
answered on 10 Apr 2012, 08:23 AM
Hi Khushali,

I am afraid that this functionality is not supported and I cannot suggest another workaround for that case.
As an alternative to the template, you could use a custom formatting, but that solution will work only if you know how long the resulting string should be. As an example: http://jsfiddle.net/valchev/vTsGY/9/ 
 
Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Khushali
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Khushali
Top achievements
Rank 1
Share this question
or