grid.dataItem(selectedRow)
this is return the selected row which is a kendo.data.ObservableObject.
this object has all the columns for that grid's selected row. Is there a way to iterate thru all the columns and update.
or do i have to do it like this:
dataitem.set("Id", 1);
dataitem.set("name", Eric);
dataitem.set("age", 12);
As far as I understand what you are trying is to copy one JavaScript object into a Grid item, correct?
Let's assume that you have the new value in val
:
var val = {
Id : 1,
name: "Eric",
age: 12
};
And you want to copy it in the selected row.
There are several ways of doing it:
- What you just did.
- Iterate through the different keys of
val
and copy the value.
- Use jQuery extend.
Option 2.
for (var key in val) {
if (val.hasOwnProperty(key)) {
dataitem.set(key, val[key]);
}
}
Option 3.
$.extend(item, val);
item.set("uid", kendo.guid());
The first instruction performs a deep copy of val
into item
.
The second instruction makes the item dirty
by just changing the UID.
NOTE: You don't need to update every single field using set
, is enough changing one and all will get updated.