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?
Asked
Active
Viewed 206 times
0
-
What have you tried? "Getting Notified" is the basic concept of observables in knockout. – xdumaine Feb 13 '14 at 19:18
1 Answers
0
Its easy achieved with some creative overrides of the kg.grid constructor
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

Anders
- 17,306
- 10
- 76
- 144