knockout.js - Kendo-Knockout: Binding "selected" viewmodel property with grid -


im using rpniemeyer`s kendo-knockout library bind viewmodel kendoui grid. subscribe change event of grid, can update corresponding viewmodel item.

i bound observablearray object's this:

{   address: "street name"   clientnumber: 1337   namepartner: "client name"   selected: false } 

now, selected property set true when corresponding row selected (the change event of kendoui grid). think should using knockoutjs custom binding handler.

i found http://jsfiddle.net/d3rsk/155/, doing kind of same. problem example gives error's in console, binding separate 'selecteditem' observable, while bind property within observablearray.

thanks in advance.

it not seamless want, can this:

  • add handler change event
  • get selected row element using grid's select method
  • from row element data item using grid's dataitem method
  • this dataitem clean object, take unique key (clientnumber in case) , use find original item in observablearray.

something like:

<div id="grid" data-bind="kendogrid: { data: items, sortable: true, selectable: true, change: updateselected, columns: ['address', 'clientnumber', 'namepartner'], widget: grid }"></div> 

with updateselected method on view model like:

updateselected: function() {     var grid = viewmodel.grid(),         row = grid.select(),         clientnumber = grid.dataitem(row).clientnumber,         actualitem = ko.utils.arrayfirst(viewmodel.items(), function(item) {            return item.clientnumber === clientnumber;         });      if (actualitem) {         actualitem.selected = true;          if (viewmodel.previouslyselected) {             viewmodel.previouslyselected.selected = false;            }          viewmodel.previouslyselected = actualitem;     }                  return true; } 

sample: http://jsfiddle.net/rniemeyer/7mxfj/

you consider attempting move logic custom binding added next kendogrid binding.


Comments