My requirement is to loop through all selected rows of a grid and set a field on the datasource with a given value. I have the following code and iterate through selected rows of a kendo ui grid.
$('#grid').data("kendoGrid").select().each(function () {
if($('#grid').data().kendoGrid.dataSource.data()[$(this).index()] != null ){
var myItem = $('#grid').data().kendoGrid.dataSource.data()[$(this).index()];
myItem.set(myFiled, myValue);
leg.push(myItem);
}
});
The problem is that after my code reaches on the line myItem.set(myFiled, myValue); the index gets the value -1 and it keeps this value even on my next iteration.
When removing the .set method i see that i do not have the same behaviour and my index keeps the correct value. Why is is this happening ?
Furthermore, what is the difference between the line:
i) $('#grid').data("kendoGrid").dataItem($(this)).set(myField, myValue);
ii) $('#grid').data().kendoGrid.dataSource.data()[$(this).index()].set(myField, myValue);
I know that the first has to do with the values on the grid. Unfortunately i never managed to set the values as shown on (i) . The code shown on line (i) does not seem to work with the set function at all.
I took my examples from here Refresh a single Kendo grid row and Kendo-UI grid Set Value in grid with Javascript for the cases (i) and (ii) .
set
s. – OnaBai