I don't know what is wrong with my implementation but I can't get my viewmodel updated if I'm using editable KendoUI Grid with Knockout-Kendo. If I change some particular table field and log the viewmodel it will not get any update.
<button data-bind="click: log">Log ViewModel</button>
<div id="gr" data-bind="kendoGrid: options"></div>
var pStyleHeader_ViewModel = function() {
this.options = {
data: ko.observableArray([{ StyleNo : ko.observable("1BA0012"),
Description : ko.observable(""),
StyleType : ko.observable("10"),
DueDate : ko.observable(new Date("2012-10-31T00:00:00+02:00"))}]),
sortable: true,
columns: [{"field":"StyleNo","title":"Style No"},{"field":"Description","title":"Description"},{"field":"StyleType","title":"Style Type","editor":StyleTypeDropDownEditor,"values":StyleTypeValues},{"field":"DueDate","title":"Due Date","type":"date","format":"{0:MM/dd/yyyy}"}],
editable: true,
selectable: true,
pageable: { pageSize: 5 }
};
ko.applyBindings(new pStyleHeader_ViewModel());
You can see an example here: http://jsfiddle.net/aleksanderson/hd5c8/
What is the reason of such behavior?
Thanks in advance.
The dataSource to KO integration is not seamless at the moment. Since, the Kendo widget does not know how to handle observables directly, ko-kendo provides a "clean" version of the data to the widget. This means that updates to that data are not automatically represented in the view model data.
I am looking to explore better dataSource integration with Knockout (likely a KO datasource) where autoSync would update the view model. This is something that will hopefully be happening in the short term.
For now, there are patterns that you can use to sync the data from the grid to your vm.
Sample: http://jsfiddle.net/rniemeyer/73mjn/
Here is a sample view model: