Good Day,
I am actually looking to find a way to save only filter, sort and current paging options when a user interract with the grid. I have seen this demo https://demos.telerik.com/aspnet-core/grid/persist-state, but I would like it to be automatically instead of having external button to do the action.
I have tried also binding on the databound event using a flag like so, but it only works the first time. My function is a little bit generic, because I would like to automatically do it for every grid in the application without having to configure anything.
let stateChanged = false;
$('.k-grid').data('kendoGrid').bind('filter', function (e) {
stateChanged = true;
});
$('.k-grid').data('kendoGrid').bind('sort', function (e) {
stateChanged = true;
});
$('.k-grid').data('kendoGrid').bind('dataBound', function (e) {
if (stateChanged) {
const grid = e.sender;
const storageKey = generateStorageKey(grid);
const options = grid.getOptions();
saveGridState(options, storageKey);
stateChanged = false;
}
});
Is there any other way to actually save the state of the grid immediately after the user interract with the grid?
Thank you :)
Finally found my mistake. I updated my code like this. Changed the order to when databound event was applied to the list :).
let stateChanged = false; $('.k-grid').data('kendoGrid').bind('filter', function (e) { stateChanged = true; }); $('.k-grid').data('kendoGrid').bind('sort', function (e) { stateChanged = true; }); $('.k-grid').each(function() { const grid = $(this).data('kendoGrid'); const storageKey = generateStorageKey(grid); loadGridState(grid, storageKey); grid.bind('dataBound', function (e) { if (stateChanged) { const grid = e.sender; const storageKey = generateStorageKey(grid); const options = grid.getOptions(); console.log(e); saveGridState(options, storageKey); stateChanged = false; } }); });