I am using SlickGrid with knockout.js using the example http://jsfiddle.net/rniemeyer/A9NrP/
I have a grid fill and an add button that works according to an example. The problem I am facing is when I update the rows property of my view model through ko.dependentObservable, the update section of ko.bindingHandlers starts, but the weak grid does not accept the changes.
html that defines the binding:
<div id="grid" data-bind="slickGrid: { data: rows, columns: columns }"></div>
SlickGrid code (same as in the example):
var grid; ko.bindingHandlers.slickGrid = { init: function (element, valueAccessor) { var settings = valueAccessor(); var data = ko.utils.unwrapObservable(settings.data); var columns = ko.utils.unwrapObservable(settings.columns); var options = ko.utils.unwrapObservable(settings.options) || {}; grid = new Slick.Grid(element, data, columns, options); }, update: function (element, valueAccessor, allBindingAccessor, viewModel) { var settings = valueAccessor();
my model:
myViewModel = { data : ko.observableArray(), tabs: ['High', 'Medium', 'Low'], rows : ko.observableArray([]), columns : [ { id: "id", name: "ID", field: "id" }, { id: "Location", name: "Location", field: "Location" }, { id: "Comment", name: "Comment", field: "Comment" } ], addItem: function() {
}
The code that makes the ajax call and runs ko.bindingHandlers.slickGrid.update, but slickgrid does not seem to pick up the changes, ajax really returns valid data and quits when the user clicks on the link:
ko.dependentObservable(function () { if (this.data.lastAlarmRequest) this.data.lastAlarmRequest.abort(); this.data.lastAlarmRequest = $.get("/audit/alarmsdata/high", null, this.rows); }, i2owater.viewmodels.AlarmsForViewModel);
Why does the addItem function work, but not ko.bindingHandlers.slickGrid.update? In the update function, I can see the correct data to which the grid is attached. Is it because all the data in the row properties is overwritten?
UPDATE: I tried using grid.invalidate (); but it does not work and also saw that the addItem function stops working after ko.dependentObservable is executed