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

Persist column selection in cookie

1 Answer 274 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Masoud
Top achievements
Rank 1
Masoud asked on 21 May 2013, 02:38 PM

Hi,

this issue is a followup on this thread!

I am trying to extend the example to persist column state in a cookie. Users can hide/show/resize columns. I thought I could use the same method described in the thread above. Here is my code:

// Add handlers to show and hide events
    .Events(events => events.ColumnHide("onColumnHideIOrShow"))
    .Events(events => events.ColumnShow("onColumnHideIOrShow"))

 

// Function is called when a column is hidden or Shown
  
function onColumnHideIOrShow(e) {
    var columnlistCookieName = "GridMarColumns";
    var grid = $("#GridMar").data("kendoGrid");
    var columns = grid.columns;
    var serializedColumns = kendo.stringify(columns);
    $.cookie(columnlistCookieName, serializedColumns);
    }

 

// On load recreate the column list as  found in the cookie
        $(document).ready(function () {
            var columnlistCookieName = "GridMarColumns";
            var serializedColumns = JSON.parse($.cookie(columnlistCookieName)); 
            var grid = $("#GridMar").data("kendoGrid");
  
            if (serializedColumns) {
                grid.columns = serializedColumns;
            }
}

When I hide a column from the grid, the column is hidden and I can see that the cookie now has the right information. When I reload the page however, the column is present in the grid, in the columnmenu however, it is no longer there (see image attached). The columns strasse is visible on the gird, but not in the list of columns that I could make visible or invisible.

Thank you for your suggestions on this issue!

1 Answer, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 22 May 2013, 07:14 AM
Hello Klaus,

Did you try to pass the columns to the configuration object when the Grid is initializing?

Since what you are trying to achieve is not supported out-of-the-box and I can suggest you to take a look at the solution created and shared by the other users using Kendo. I guess it might be of help!

http://blogs.planetsoftware.com.au/paul/archive/2013/04/10/extending-kendo-grid-functionality-with-knockout.aspx


Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Masoud
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or