【发布时间】:2020-12-02 13:13:53
【问题描述】:
默认情况下,我需要在编辑模式下将空的最后一行添加到 Kendo UI 网格。我从 api 获取数据,如果我最后尝试添加空行,它会首先被调用,然后 api 会被调用。我该怎么做。我不想设置超时。我尝试在数据源中添加空记录,但为此我需要做很多事情
var dataSource = new kendo.data.DataSource({
type: "odata",
serverPaging: false,
serverSorting: false,
serverFiltering: false,
//pageSize: 20,
schema: {
data: function (data) {
var resultData = [];
if (data.value != null && data.value[0].Payload != null && data.value[0].Payload != "[]")
resultData = JSON.parse(data.value[0].Payload);
return resultData;
},
total: function (data) {
var length = 0;
if (data.value != null)
length = data.value[0].PayloadCount;
return length;
},
model: {
id: that.gridProperties.PrimaryKeyName,
fields: that.gridProperties.Schema
}
},
change: that.onGridDataChanged,
transport: {
read: {
url: that.gridProperties.DataSourceURL,
contentType: "application/json; charset=utf-8",
type: "GET",
dataType: "json"
}
}
});
$('#' + that.gridProperties.ControlId).kendoGrid({
height: "100%",
scrollable: true,
filterable: true,
sortable: true,
resizable: true,
pageable: false,
noRecords: true,
editable: that.gridProperties.Editable,
selectable: !that.gridProperties.AllowMultiSelect, //If multiselect is false enable row selection
columns: gridColumns,
dataSource: dataSource,
edit: that.onGridEdit,
// This is required to update the calculated column as soon as user enters/types new values
save: function (e) {
var dataSource = this.dataSource;
that.updateFormulaColumn(e, dataSource);
e.model.one("change", function () {
dataSource.fetch();
});
},
});
var grid = $('#' + that.gridProperties.ControlId).data("kendoGrid");
grid.addRow()
【问题讨论】:
-
默认情况下没有魔法,网格渲染行不是想象的有它渲染的数据源所以添加到数据源。即使您使用按钮添加新行,它也会作为空行进入您的数据源。
标签: javascript jquery kendo-ui kendo-grid kendo-ui-grid