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

Persist state - data source urls

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 21 Apr 2015, 10:18 PM

Hi

We are using the grid getOptions/setOptions to persist the users filters, column settings etc to a cookie

An issue we now have is it seems to persist everything including the datasource urls for read/update. This is an issue for us as we use custom MVC routes which look something like this: /jobs/1234/deliverable so the id is embedded into the url. When this is persisted the grid ends up querying data for a previously used Id.

 

What is the best way to prevent persisting the datasource url information and always use the URL as defined in the html page?

We have managed to get it working by doing this:

function loadGridState(grid, sessionKey) {
    var options = localStorage[sessionKey];
    if (options) {
        var parsedOptions = JSON.parse(options);
        parsedOptions.dataSource.transport.read = grid.dataSource.transport.options.read; //dont persist datasource urls
        grid.setOptions(parsedOptions);
    }
}

 

Is there a better way to do this and is there anything else we should be preventing (e.g. update, delete) if this were to be a generic function for the entire project?

 

One other strange we noticed is the object stored from getOptions is a slightly different structure to that directly on the grid.

E.g. the Grid has dataSource.transport.options.read but the getOptions stores dataSource.transport.read

 

Thanks

Andy


1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 24 Apr 2015, 06:08 AM
Hi Andy,

If the stored Grid options should be modified before being used, then you should do exactly what you are doing now - manually tweak values in the settings object before using setOptions().

dataSource.transport.options.read is an internal merged object of the default transport's read prototype values and the values in the Grid configuration

dataSource.transport.read (returned by getOptions() ) provides the proper structure, which matches the Grid dataSource configuration API and is suitable for initializing a Grid dataSource transport instance.

https://admin.telerik.com/dataSource.transport.read

Regards,
Dimo
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or