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.