以下是代码的精简版本:
gridDataSource = new kendo.data.DataSource({
batch: true,
transport: {
read: {
url: 'Equipment'
},
destroy: {
url: 'Equipment',
contentType: "application/json",
dataType: 'json',
type: "DELETE"
},
parameterMap: function (options, operation) {
if (operation == "read") {
return "this=works-fine";
} else {
alert('not reading');
return kendo.stringify(options.models);
}
}
},
schema: {
id: "EquipmentId",
fields: {
Value: { type: "number" }
}
}
});
kendoGrid = gridObj.kendoGrid({
dataSource: gridDataSource,
selectable: 'row',
navigatable: true,
change: rowSelect,
sortable: true,
pageable: false,
columns: [
{ field: "Value" },
]
}).data('kendoGrid');
读取工作正常,我删除了一行(或多行)(selectedRow正确填充,只是为了简洁而跳过):
$('#footer-remove').off().on('click', function () {
kendoGrid.removeRow('table tr[data-uid="' + selectedRow.uid + '"]');
console.log(gridDataSource._destroyed);
});
它显示在gridDataSource._destroyed中,我的所有测试都显示gridDataSource是脏的。
当我调用同步时,如果我只是删除则没有任何反应。我错过了什么?谢谢。
答案 0 :(得分:1)
您需要在editable
的初始化中将true
设置为grid
。
kendoGrid = gridObj.kendoGrid({
dataSource: gridDataSource,
selectable: 'row',
navigatable: true,
change: rowSelect,
sortable: true,
pageable: false,
editable: true,
columns: [
{ field: "Value" },
]
}).data('kendoGrid');
如果您不希望单元格可更新(只是被删除),那么您应该设置editable
如下:
editable: {
destroy: true,
update: false
},
此外,将editable.confirmation
设置为false
会在删除时禁用弹出提示进行确认。
编辑:
destroy
未执行的原因是Datasource
定义中存在错误,schema
应包含model
元素然后定义(您错过了) model
)。
schema: {
model: {
id: "EquipmentId",
fields: {
Value: { type: "number" }
}
}
}
您可以在此处看到它:http://jsfiddle.net/OnaBai/dq6jh3yp/4/