簡體   English   中英

編輯網格時,如何按行禁用特定字段?

[英]When editing a grid, how do I disable specific fields by row?

我有一個帶有數據的kendo網格和多個列(比如col 1,2和3)。 第1,2,3列需要能夠根據彼此的值進行編輯(或防止編輯)。 這是特定於行的。

例如,如果第1列(日期)是<第2列(日期),則不允許編輯第3列。

我知道禁用或啟用整個列很簡單,但我的要求是特定於行的。 因此,第1行可以啟用第3列,第2行可以禁用第3列。

有什么想法嗎?

我的建議是創建一個驗證條件的編輯器功能。 這當然有一個缺點,即一個臨時解決方案,但......它的工作原理!

讓我們有以下條目(DataSource的數據):

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

我生成相​​應的input字段,如果col1 < col2 ,否則調用closeCell退出edit模式。

你可以看到它在這里運行

保持簡單只是使用(你在網格列中綁定)

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

在用於Kendo Ui Grid的Costume類中。

有關詳細信息,您也可以看到這一點

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM