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

Loading persisted state refreshes data

1 Answer 320 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 02 Aug 2016, 07:53 PM
var grid = $(ViewModel.gridName()).data("kendoGrid");
//Reset all existing sorts/filters first.  If the persisted view didn't have them set, the 
//existing state and persisted state are merged.
grid.dataSource.sort({});
grid.dataSource.filter({});
 
grid.setOptions(JSON.parse(targetView.GridOptions()));

 

I'm using the setOptions method to restore the state previously obtained from grid.getOptions().  My data is small enough that I load it completely client side.  When I call set options, the grid reloads the data from the server.  It works fine, but it's unnecessary.

Is there an option to avoid reloading the data from the server after setOptions is called?

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 04 Aug 2016, 03:25 PM
Hi Joel,

When the setOptions() method is called, the Grid is destroyed and recreated. If the widget is bound to remote data, a new read request will be made:

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-setOptions

There are couple of workarounds to avoid multiple calls:

1) You can retrieve the data independently from the Grid (e.g. via $.ajax()), and store it in a variable, then bind the Grid to this array instead of to the remote service:

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-dataSource

2) If the Grid is loaded with the saved settings on page load, you can initially configure it with autoBind: false, and then remove the autoBind property from the options object, before passing it to the setOptiions() method. This approach will ensure that only one read request is fired (after the call to setOptions()), but is applicable only if the Grid data is not supposed to be used before the call to setOptions() (for example when the Grid is loaded on page load with different settings, based on the current user).

I hope this helps.

Regards,
Dimiter Topalov
Telerik by Progress
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Tags
Grid
Asked by
Joel
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Share this question
or