Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Kendo UI Grid from rebinding many times when updating ViewModels

When you bind to a Kendo UI Grid with MVVM, databound will fire once and all is well. If you need to update that data after the fact, every time you change one piece of data on any viewmodel (or child viewmodel), the entire grid re-databinds. Thus, if you had some cell in the grid that is bound to a template and you have to change 2 or 3 properties on the viewmodel from some external ajax source, Databound will fire 2 or 3 times for each model that is changed, causing the entire viewable area to rebind. How can we update lots of data at once and only have databound fire once?

like image 271
Daniel Lorenz Avatar asked Mar 22 '13 21:03

Daniel Lorenz


1 Answers

How exactly you rebind the Grid? Basically if you change some of the models like this:

dataItem.set('SomeField','new value');
dataItem.set('someOtherField','other value');

This way the Grid will be indeed bound two times because of the MVVM. The change event is triggered each time you call set.

However if you update the values like this:

dataItem.SomeField='new value';
dataItem.someOtherField= 'other value';

The Grid wont react to the change and wont rebind re-read the values from the models you can force the Grid to do it through the refresh method.

$('#gridName').data().kendoGrid.refresh()
like image 172
Petur Subev Avatar answered Sep 21 '22 16:09

Petur Subev