kendo UI grid dataitem set method

帅比萌擦擦* 提交于 2020-01-02 06:07:26

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/18242682/kendo-ui-grid-dataitem-set-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!