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

How to attach custom parse and format functions to a grid column?

3 Answers 1610 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vishwa
Top achievements
Rank 1
Vishwa asked on 20 Aug 2013, 11:36 AM
Hi,
I am new to Kendo.

We have different settings for parsing and formatting data types on the server irrespective of the browser locale(culture). I have custom parsing and formatting code to display the values on the UI.

I am not finding a way to hook up custom parse and format function to the grid column. I am wondering if this is possible?

If this is possible then please point me to the example or the documentation which describes how to do this?

Thanks in advance.

Regards
Vishwa Salgia 

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 22 Aug 2013, 06:58 AM
Hello Vishwa,

Parse function of the DataSource's schema could be used to preprocess or parse the server response. This function is useful if you want to transform the date string that your server sends into JavaScript object on the client.
Format option of the column is used to customize the way JavaScript date is displayed in the Grid.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Vishwa
Top achievements
Rank 1
answered on 26 Aug 2013, 09:30 AM
Hi Alexander,

I want to display the measurement field in 2 different ways in my application.

Server sends a number(for example 16.5) and some formatting information and grid column cell displays is it as 16 1/2. When user edits editor displays 16 1/2 and lets say user modifies it to 16 3/4. When editor closes then it should be displayed as 16 3/4. The value of the cell should be 16.75 now.


Another use case: Server sends 16.5, 'mm' and some formatting information and grid column cell displays it as '16.5 mm' as the display unit of measure is millimeter.  When user edits it  editor displays it as 16.5 mm ans lets say user modifies it to '0.5 in'. When editor closes it needs to be parsed as 12.7 as number and grid cell needs to display the 0.5 in as user choose to see it in inches instead of millimeter. On submit I need to submit 2 values as number =12.7 and displayUOM=Inch.

Please suggest how can I achieve this with the kendo grid.

Regards
Vishwa Salgia
0
Petur Subev
Telerik team
answered on 28 Aug 2013, 06:46 AM
Hello Vishwa,

To change how a property is displayed in the Grid you should use the template of the column. Template of the column can execute JavaScript (event external function that can handle the formatting for you).

http://docs.kendoui.com/api/web/grid#configuration-columns.template

http://docs.kendoui.com/api/framework/kendo#methods-template

http://docs.kendoui.com/getting-started/framework/templates/overview

How the editor of the column will look like is handled by the editorTemplate for that column.

http://docs.kendoui.com/api/web/grid#configuration-columns.editor

Check the following demo how to customize it:

http://demos.kendoui.com/web/grid/editing-custom.html

However whatever value is send from the editor template - the same value will be used to update the model. To change this (parse the value and update the model with different value you can use the edit event of the Grid)

Kind Regards,
Petur Subev
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
Vishwa
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Vishwa
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or