I have a view-model with a property called fields that is attached to my datasource's view, which will have some data similar to this:
I'm using the following row-template to make a sort of grid with a column that has an edit button in it.
This all works great until the click event (edit function in view-model) is called. While I am inside the edit function I can not use the get or set functions to work with the data unless I state the index of the entry from the view-model I want to edit.
This will only works as long as the Ids in my data start at 1 and are always sequential, which is not very likely. You can see this here (http://jsfiddle.net/garrett55/aYMRn/) in the fiddle I created for this post.
Am I missing the right way to do this? Is there an easier way to get the index of the data I want in the view-model?
[{ Id: 1, Name: 'Email', Type: 'Email', Default: '', Display: true, Identifier: true}, { Id: 2, Name: 'First name', Type: 'Text', Default: 'Fistname', Display: true, Identifier: false}, { Id: 3, Name: 'Last name', Type: 'Text', Default: 'Lastname', Display: true, Identifier: false}, { Id: 4, Name: 'City', Type: 'Text', Default: '', Display: true, Identifier: false}]I'm using the following row-template to make a sort of grid with a column that has an edit button in it.
<script id="row-template" type="text/x-kendo-template"> <tr data-uid="#= Id #"> <td align="center"> <a href="javascript:void(0);" data-bind="click: edit" class="editRow">edit</a> </td> <td data-bind="text: Name"></td> <td data-bind="text: Type"></td> <td data-bind="text: Default"></td> <td align="center"><input type="checkbox" data-bind="checked: Display" /></td> <td align="center"><input type="checkbox" data-bind="checked: Identifier" /></td> </tr></script>This all works great until the click event (edit function in view-model) is called. While I am inside the edit function I can not use the get or set functions to work with the data unless I state the index of the entry from the view-model I want to edit.
edit: function(e){ this.set('fields[' + (e.data.Id -1) +'].Default', 'Clicked');}This will only works as long as the Ids in my data start at 1 and are always sequential, which is not very likely. You can see this here (http://jsfiddle.net/garrett55/aYMRn/) in the fiddle I created for this post.
Am I missing the right way to do this? Is there an easier way to get the index of the data I want in the view-model?