4

我有一个剑道网格,其中包含数据和多列(例如 col 1、2 和 3)。第 1、2、3 列需要能够根据彼此的值进行编辑(或阻止编辑)。这是特定于行的。

例如,如果第 1 列(日期)< 第 2 列(日期),则不允许编辑第 3 列。

我知道禁用或启用整个列很简单,但我的要求是特定于行的。因此,第 1 行可以启用第 3 列,第 2 行可以禁用第 3 列。

有什么想法吗?

4

2 回答 2

14

我的建议是创建一个验证条件的编辑器函数。这当然具有临时解决方案的缺点,但是......它有效!

让我们有以下条目(数据源的数据):

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");

where col1and col2are dates and是一个字符串,当且仅当小于时才col3可以编辑。 col1col2

我定义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);
    }
}

如果<则在哪里生成相应的input字段,否则为退出模式调用。col1col2closeCelledit

你可以看到它在这里运行

于 2013-01-09T00:02:40.093 回答
3

保持简单,只需使用(在网格列中绑定)

[Editable(false)]
public string ob_name { get; set; }

在用于 Kendo Ui Grid 的服装类中。

有关详细信息,您还可以查看此

于 2013-05-13T04:42:42.220 回答