Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kendo UI grid dataitem set method

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);
like image 522
WingMan20-10 Avatar asked Mar 23 '23 18:03

WingMan20-10


1 Answers

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:

  1. What you just did.
  2. Iterate through the different keys of val and copy the value.
  3. 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.

like image 57
OnaBai Avatar answered Apr 10 '23 09:04

OnaBai