我的建议是创建一个验证条件的编辑器函数。这当然有一个临时解决方案的缺点,但是......它有效!
让我们有以下条目(数据源的数据):
var entries = [
{ id:1, col1: new Date(2012, 11, 31), col2: new Date(2013, 0, 1), col3: "Yes" },
{ id:2, col1: new Date(2013, 0, 1), col2: new Date(2013, 0, 1), col3: "No" },
{ id:3, col1: new Date(2013, 0, 2), col2: new Date(2013, 0, 1), col3: "No" }
];
然后我将网格定义为:
var grid = $("#grid").kendoGrid({
dataSource : {
data : entries,
schema : {
model: {
id : "id",
fields: {
col1: { type: "date"},
col2: { type: "date"},
col3: { editable: true }
}
}
},
pageSize: 3
},
columns : [
{ field: "col1", title: "Col1", format: "{0:yyyy-MM-dd}" },
{ field: "col2", title: "Col2", format: "{0:yyyy-MM-dd}" },
{ field: "col3", title: "Edit?", editor: checkAndEdit }
],
editable : "incell",
navigatable: true,
pageable : true
}).data("kendoGrid");
其中col1 和col2 是日期,col3 是可以编辑的字符串当且仅当 col1 小于col2。
我定义checkAndEdit函数如下:
function checkAndEdit(container, options) {
if (options.model.col1 < options.model.col2) {
$('<input data-bind="value:' + options.field + '" ' +
'data-format="' + options.format + '" ' +
'class="k-input k-textbox"/>')
.appendTo(container);
} else {
grid.closeCell(container);
}
}
如果col1 col2 则我生成相应的input 字段,否则调用closeCell 以退出edit 模式。
你可以看到它在运行here