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

How to re-render grid with new columns/data after fetch from dataSource

4 Answers 251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JS
Top achievements
Rank 1
JS asked on 18 Feb 2012, 01:45 AM
I have a grid that is metadata driven. When the data comes back from the data source (the data that comes back includes the metadata), I parse the data with the parse method. In that method, I flatten a data structure that I received to match a list of columns that we generated by the metadata.

I have set the dataSource property of the grid to the kendo datasource that I created.

I have some actions in the page that can force the datasource to fetch its data and metadata (through dataSource.fetch). The problem that I have is it seems that I can't force the grid to update its list of columns and its data at the same time unless I completely destroy the html containing the grid.

Furthermore, the grid will also trigger a fetch of the data when it is re-rendered, causing two calls to the server to do exactly the same thing.

Is there a way to force the grid to fully re-render itself while using the data that is already in the dataSource? I tried calling dataSource.data() but it returns an empty object, although there is actually some data in the dataSource (it may have to do with the cache=false in my settings)

Thanks

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 22 Feb 2012, 01:54 PM
Hello,

I'm afraid that our Grid currently does not support changing the columns once set. Therefore, you may consider recreating the entire widget instead.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Vallelunga
Top achievements
Rank 1
answered on 24 Feb 2012, 05:34 PM
I'm in need of this same functionality. Let me give you a concrete example.

I am showing data from a report. The columns show either data by day, week, month, etc. When a user changes a grouping option, I get the new data, which may then have more or less columns. It would be great if the grid would rebuild itself with the new columns.
0
Brian Vallelunga
Top achievements
Rank 1
answered on 24 Feb 2012, 05:52 PM
As a follow-up, what I really want to do is to recreate the column area of the grid, but not the toolbar. Because I have controls in the toolbar area of the grid, these get removed from the grid as well and thus can't keep their state.
0
Jeremy
Top achievements
Rank 1
answered on 24 Feb 2012, 10:58 PM
I believe the best thing to do is concentrate on a strategy that will recreate the grid when different columns are needed

I had a post here describing my solution
http://www.kendoui.com/forums/ui/grid/hide-columns.aspx#2001610 

And as far as the toolbar state, you'll have to maintain the state locally, and reset it when the grid is recreated.
Tags
Grid
Asked by
JS
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Brian Vallelunga
Top achievements
Rank 1
Jeremy
Top achievements
Rank 1
Share this question
or