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

查看:30
本文介绍了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?

谢谢

推荐答案

基本上当你想更新一个记录时,你应该使用 set 模型的方法.例如要更新数据源的第一条记录,您应该像这样更新它:

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

上面应该会自动将flag标记为dirty并通知Grid有变化,所以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天全站免登陆