javascript - KendoUI - 使用底层模型从网格单元读取编辑的数据

标签 javascript kendo-ui

下面我有一个 kendoUI 网格,它从服务器获取数据。然后,用户可以编辑网格中的两列。我有一个单独的按钮,可以将数据发送回服务器,并且我不使用剑道网格的 UPDATE 传输来执行此操作。我遇到的问题是,如果我从网格中获取数据,它不会反射(reflect)用户输入。例如,要获取网格的基础数据,我执行以下操作:

products= $("#Grid").data("kendoGrid").dataSource.data()

但是当我迭代产品并检查 NewPrice 或 Comment 属性时,它始终为空白。以下是网格数据源的定义方式:

dataSource: {
  transport: {
    read: function (options) {
      $.ajax({
        url: "/Portal/API/GetProductPrices?id=" + pId,
        dataType: "json",
        success: function (data) {
          localModel.userId = data.userId;
          localModel.products = data.Products;
          return options.success(model.products);
        },
      });
    }
  },
},
scrollable: false,
selectable: true,
schema: {
  model: {
    id: 'Id',
    fields: {
      Item: { type: 'string', editable: false },
      Price: { type: 'number', editable: false },
      NewPrice: { type: 'number', editable: true },
      Comment: { type: 'string', editable: true, validation: { required: true } },
    }
  }
},
columns: [
  { field: "Price", title:"Price"},
  {
    field: "NewPrice", title: "<span class='editMode'>Proposed Value</span>", format: "{0:p}", attributes: { style: "text-align:center;" }, headerAttributes: { style: "text-align:center;" }, width: "50px",
    template: "#=NewValueTemplate(data)#",
  },
  { field: "Comment", title: "<span class='editMode viewWorkflowMode'>Notes</span>", width: "210px", template: "#=NotesTemplate(data)#" },
]

任何解决问题的建议将不胜感激

最佳答案

您尚未指定您正在使用的编辑类型。
您使用哪种类型:内联、批量或弹出

只有这个是数据源吗?我没有看到更新功能。
我建议你看一下这三个演示。
Batch
Inline
Popup

最糟糕的是您没有指定editable属性的值。
默认情况下,它是 false,这意味着 kendoGrid 不可编辑,
即使您在模型字段上指定了 editable: true

Shortcut to "Editable" configuration

更新#2:

正如已经说过的here

If the data source is bound to a remote service (via the transport option) the data method will return the service response.

因此,当您在网格上使用 dataSource.data() 方法时,如果您没有正确更新数据源,您应该收到所有“旧”数据。 (我发现很奇怪,你在这些属性上得到空白值,可能是缓存问题)

正如我已经说过的,您的数据源不提供更新功能。

Here您是有关kendo dataSource中更新功能的配置的示例,其中包含对远程服务的请求。

建议您查看这两个示例:

示例 - 将更新指定为字符串 示例 - 将更新指定为函数

关于javascript - KendoUI - 使用底层模型从网格单元读取编辑的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29338867/

相关文章:

jquery - Kendo上传控件,将自定义错误消息传递回查看

c# - 如何在 mvc kendo 网格的 ajax 绑定(bind)中使用客户端模板表达式?

javascript - 如何纠正IE8原生json中的字符编码?

kendo-ui - 如何在 asp.net mvc 中禁用剑道编辑器

javascript - 如何使用angularjs将数据传递到kendo窗口

javascript - $firebase 在 AngularJS 中未定义

javascript - 将网格内的 DropdownList 值传递给网格本身

javascript - 如何使用 javascript 或 jquery 返回样式表中样式的 css 属性的值?

javascript - 我正在尝试使用 momentjs 将变量转换为日期

javascript - Node.js,使用单个 readline 读取多个文件