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

Change formatting of Grid column in response to event

1 Answer 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leader
Top achievements
Rank 1
Leader asked on 11 Dec 2013, 11:09 AM
Hello,
I have a Kendo Grid (called 'overallGrid' in my example) with some columns formatted as percentages with one decimal place ( format: "{0:p1}" ). I also have a View Model with a Select element, where the user can change what values they wish to see in the columns. What I need to do is, when they pick a certain option in the Select element, the formatting of the columns should be changed to be a decimal with 1 decimal place, rather than a percentage.

At the moment, I have this in the "click" event of a "update grid" button;
if (viewModel.score == 'Mean') {
    overallGrid.columns[1].format = '{0:n1}';
    overallGrid.columns[3].format = '{0:n1}';
}
overallGrid.dataSource.filter(  [
    { field: "score",      operator: "eq", value:viewModel.score},
]);
overallGrid.dataSource.read();
overallGrid.refresh();
When run, the formatting on the rendered grid does not change, even though I can see that the "columns.formatting" of the Grid object has been changed when I inspect the object in Firebug.

What am I doing wrong? Thanks!

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 12 Dec 2013, 08:33 AM
Hello Andrew,

I'm afraid that the column format option cannot be changed after grid initialization. However, you may achieve similar to the described functionality by using a column template to apply different formatting. Here you can find a test page which demonstrates a basic implementation.

Also as a side note, looking at the code snippet you have pasted, there is no need to call DataSource's filter, read as well as grid refresh. It is sufficient to call just filter, it will automatically trigger grid refresh.

Regards,
Rosen
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
Leader
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or