0

I have a KoGrid and want to be able to save visible columns when a user revisits the page. I would save data in json to a cookie or on the database, but how can I get notified when a column's visible attribute is changed, and load visibility on initialization?

1 Answers1

0

Its easy achieved with some creative overrides of the kg.grid constructor

http://jsfiddle.net/A29GA/2/

var savedState = { age: false, name: true };

var org = kg.Grid;
kg.Grid = function (options) {
    var grid = new org(options);

    ko.utils.arrayForEach(grid.columns(), function(col)  {
        //load state from cookie                          
        col.visible(savedState[col.field]);

    });

    grid.visibleColumns.subscribe(function() {
        console.log("Here you get notified when visible columns change save to cookie");
    });

    return grid;
};

Here is a example that uses actual cookies, but I wouldnt rely on the cookie code, its quick and dirty

http://jsfiddle.net/A29GA/3/

Anders
  • 17,306
  • 10
  • 76
  • 144