Kendo-UI网格使用Javascript设置网格中的值 [英] Kendo-UI grid Set Value in grid with Javascript

查看:142
本文介绍了Kendo-UI网格使用Javascript设置网格中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何在JavaScript中更改网格中的一行值,以便在网格和底层数据源中将其标记为脏。

I'm just wondering how you go about changing a value of a row in a grid in JavaScript so that it is marked as 'dirty' in the grid and the underlying datasource.

例如我有一个联系人/客户的列表。他们有3个字段FirstName / LastName / IsPrimaryContact。只能有1个主要联系人,因此当主要联系人在记录上设置为true时,我将JavaScript代码循环遍历数据源,并将任何设置为主要的联系人设置为false。

e.g. I have a list of Contact/Customer. They have 3 fields FirstName/LastName/IsPrimaryContact. There can only be 1 primary contact, so when the primary contact is set to true on a record I have JavaScript code that loops through the datasource and sets any other contacts set as primary to false.

JavaScript全部触发,数据字段设置正确,但有两个问题:
1.网格不会随着我在数据源下的更改而更新
2 。改变的记录没有被标记为脏,因此当我调用Datasource.sync()时,不会同步回复。

The JavaScript all fires fine and the data fields are set correctly but there are two problems: 1. The grid is not updated with the changes I make under the hood to the datasource 2. The records changed are not marked as "dirty" and therefore not sync'd back when I call a Datasource.sync()

我可以手动修复第二个问题设置记录上的脏字段,但这似乎不正确。感觉就像我应该在网格级更新这个字段,以便它在UI和数据源中都处理它。

I can fix the second issue by manually setting the dirty field on the record, but this doesn't seem right. It feels like I should be updating the field at the grid level so that it takes care of it in both the UI and the datasource.

有关如何去做的任何想法这个?

Any ideas on how to go about this?

谢谢

推荐答案

基本上当你想更新记录您应该使用模型的 设置 方法。例如,要更新dataSource的第一条记录,您应该如下更新:

Basically when you want to update a record you should use the set method of the model. For example to update the first record of the dataSource you should update it like this:

var firstItem = $('#GridName').data().kendoGrid.dataSource.data()[0];
firstItem.set('FirstName','The updated Name');

上面应该自动将标志标记为脏,并通知Grid有变化,所以网格将自动刷新

The above should automatically mark the flag as dirty and it will notify the Grid that there are changes, so the Grid will automatically refresh.

另外如果要直接检索与特定行相关的对象,可以使用网格的 dataItem 方法。

Also if you want to retrieve the object related to a specific row directly you could use the dataItem method of the Grid.

这篇关于Kendo-UI网格使用Javascript设置网格中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆