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

Reset localStorage after new column added

3 Answers 447 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 04 Jun 2019, 02:33 PM

I added a new column to my grid but it's not showing up because I'm using the setOptions method along with localStorage to save the grid options and it must be overriding the grid columns. How can I reset/clear localStorage so that the grid gets updated properly in the browser? Here is the relevant JS code:

    $(function () {
        var grid = $("#reviewsGrid").data("kendoGrid");

        var options = localStorage["pat-sessions-options"];
        if (options) {
            var parsedOptions = JSON.parse(options);
            parsedOptions.toolbar = [
                { template: $("#toolbarTemplate").html() }
            ];
            parsedOptions.columns[0].headerTemplate = $("#emptyHeaderTemplate").html();
            grid.setOptions(parsedOptions);
        }
    });

    function onDataBoundPATItems(e) {
        var grid = $("#reviewsGrid").data("kendoGrid");
        localStorage["pat-sessions-options"] = kendo.stringify(grid.getOptions());
    }

3 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetina
Telerik team
answered on 06 Jun 2019, 11:06 AM
Hi Dave,

I just shared a sample snippet that shows a similar scenario in another thread. It resets the stored options if the currently declared Grid columns have a column with a field name that does not exist in the stored columns. You can see it here:
Persisted Grid Issues

Try the suggested solution and let me know if this is what you need to implement.

Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Dave
Top achievements
Rank 1
answered on 06 Jun 2019, 03:09 PM

Thank you for the suggested solution. It worked but I had to make a few small fixes to the code (bolded and italicized below):

    for(var j = 0; j < storedColumnOptions.length; j++) {
        if(currColumn.field === storedColumnOptions[j].field) {

0
Tsvetina
Telerik team
answered on 06 Jun 2019, 03:17 PM
Hi Dave,

Thanks for the follow-up and feedback. Indeed, these are errors that need to be addressed, so I updated my other post to fix them there.

Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Dave
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Dave
Top achievements
Rank 1
Share this question
or