Persist specific grid state (column width), ignore others (sort, page, ...)

1 Answer 348 Views
Grid
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
Stefan asked on 10 May 2021, 02:05 PM

Hi,

we want to persist the width of resizable columns, only.

We are aware of this article (https://demos.telerik.com/aspnet-mvc/grid/persist-state) and the getOptions() and setOptions() functions, but these get/set other options like sort and page.

We only want to persist the column width. Is there a supported way of doing this?

Kind regards.

1 Answer, 1 is accepted

Sort by
1
Accepted
Georgi Denchev
Telerik team
answered on 11 May 2021, 12:19 PM

Hello, Stefan,

You can set only the columns using the setOptions method:

            $("#load").click(function (e) {
                e.preventDefault();
                // Retrieve the options.
                var options = localStorage["kendo-grid-options"];
                if (options) {
                    // Parse the retrieved options.
                    let parsedOptions = JSON.parse(options);
                    // Get only the columns from the options.
                    let columns = parsedOptions.columns;
                    // Change only the columns options. You can use the same approach for other settings as well.
                    grid.setOptions({columns: columns});
                }
            });

Best Regards,
Georgi Denchev
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
Grid
Asked by
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Georgi Denchev
Telerik team
Share this question
or