【问题标题】:When editing a grid, how do I disable specific fields by row?编辑网格时,如何按行禁用特定字段?
【发布时间】:2012-12-22 16:48:45
【问题描述】:

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

例如,如果第 1 列(日期)

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

有什么想法吗?

【问题讨论】:

  • 要求澄清:readonly 公式是否会影响cell 或整个row 的版本?在您的示例中,不允许编辑第 3 列(取决于第 1 列和第 2 列),但是第 1 列和第 2 列会发生什么情况,是否可以编辑它们?最通用的解决方案可能需要构建一个连续单元格之间的依赖关系图,甚至检测循环依赖关系(应该被视为错误)。
  • 没有自定义编辑器的替代解决方案:stackoverflow.com/questions/20881484/…

标签: javascript kendo-ui telerik grid


【解决方案1】:

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

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

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

其中col1col2 是日期,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

【讨论】:

  • 看来这只适用于“incell”。执行“内联”时,编辑器只会触发一次,因此您不能根据另一个单元格的内容更改一个单元格。
【解决方案2】:

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

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

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

详情也可以see this

【讨论】:

  • 通过使用数据注释,这对我有用,thanx @atik sarker :)
猜你喜欢
  • 2013-08-09
  • 2012-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多