Reset localStorage after new column added

4 posts, 1 answers
  1. Dave
    Dave avatar
    42 posts
    Member since:
    Jan 2008

    Posted 04 Jun 2019 Link to this post

    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());
        }

  2. Answer
    Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 06 Jun 2019 Link to this post

    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.
  3. Dave
    Dave avatar
    42 posts
    Member since:
    Jan 2008

    Posted 06 Jun 2019 in reply to Tsvetina Link to this post

    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) {

  4. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 06 Jun 2019 Link to this post

    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.
Back to Top