我在动态剑道网格中有一列称为PassId的列,该列需要增加,但是创建新行时看不到ID。我将如何显示?
我创建了一个模型类,网格中的所有字段都必须绑定到该模型类。请让我知道如何将字段详细信息绑定到模型,并在添加新行时在网格上查看ID。
谢谢。
代码是:
iOS
<script>
$(document).ready(function () {
var testResults = [];
var dataSource = new kendo.data.DataSource({
data: testResults,
autoSync: true,
schema: {
model: {
id: "PassId",
fields: {
PassId: { editable: false },
TestCondition: { editable: true, validation: { required: true } },
ActualYield: { editable: true, nullable: true },
ControlYield: { editable: true, nullable: true },
TestDescription: { editable: true, validation: { required: true } },
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
dataBound: function (e) {
var a = e.sender.dataSource.view().length;
if (a == 2) {
var b = $("div#grid").find(".k-header");
$(".k-button").addClass("k-state-disabled").removeClass("k-grid-add");
e.preventDefault();
}
else {
$(".k-button").removeClass("k-state-disabled").addClass("k-grid-add");
$(".k-button").removeClass("k-state-disabled").addClass("k-grid-delete");
}
},
edit: function (e) {
if (e.model.isNew()) {
var id = generateID();
e.model.set("PassId", id);
}
},
remove: function (e) {
var deleted = this.dataItem(e.row);
console.log("deleted = " + deleted);
var length = this.dataSource.view().length;
},
toolbar: ["create"],
columns: [
{ field: "PassId", title: "Pass Id", width: "100px", template:"#= generateID()#"},
{ field: "TestCondition", title: "Test Condition", width: "100px",
{ field: "ActualYield", title: "Actual Yield", width: "100px"},
{ field: "ControlYield", title: "Control Yield", width: "100px"},
{ field: "TestDescription", title: "Test Description / Bin", width: "300px"},
{ command: "destroy", title: " ", width: "67px" },
],
editable: true,
editable: {
"mode": "inline",
"createAt": "bottom"
},
});
});
function generateID() {
var datagrid = $("#grid").data("kendoGrid").dataSource;
console.log("data grid", datagrid);
var numOfRows = datagrid.view().length;
console.log("num of rows", numOfRows);
var setId = datagrid.data()[numOfRows-1];
setId.set('PassId', numOfRows);
}
</script>