Kendo UI Grid:如何在条件下使单元格读取

时间:2014-06-10 13:05:18

标签: javascript jquery angularjs kendo-ui kendo-grid

在Kendo UI Grid中(使用Angularjs)我有以下网格:

<div kendo-grid k-data-source="Table" k-options="thingsOptions" style="height: 365px">

$scope.thingsOptions = {
    sortable: "true",
    scrollable: "true",
    toolbar: [{ name: "create", text: "Aggiungi Prodotto" }],
    columns: [
                { field: "Name", title: "Name", width: "50px" },
                { field: "Description", title: "Description", width: "50px" },
                { field: "Price", title: "Price", width: "50px" },
                { field: "Active", title: "Active", template: '<input type="checkbox" disabled="disabled" #= Active ? checked="checked":"" # class="chkbx"  />', width: "20px" },
                { command: [{ name: "edit", text: "Modifica" }], title: "", width: "172px" }
    ],
    editable: "inline"
};

如何在某些条件下只读“价格”字段?我必须测试一个变量,如果它是真的,我希望Price字段只读,否则可写。

我试图添加“thingsOptions”功能:

edit: function (e) {
  if(myvar == true)
        e.container.find("input[name=Price]").enable(false);
 }

但是id不起作用(未定义的引用)。

3 个答案:

答案 0 :(得分:0)

尝试使用:

edit: function (e) {
    if(myvar == true)
        $("input[name=Price]").attr("readonly", true);
    } else {
        $("input[name=Price]").attr("readonly", false);
    }
}

答案 1 :(得分:0)

在网格的编辑功能中,只需按照您想要的方式操作条件。要关闭单元格,您可以使用 this.closeCell();

      edit: function (e) {

         //Size will be editable only when the Area is not empty 
         if(e.container.find(“input”).attr(“name”) == ‘Price’) { 
           //Below statement will close the cell and stops the editing.
           if(myvar == true){
            this.closeCell();
           }
         }
        }

有关详情,请查看here

答案 2 :(得分:0)

columns: [{
                editable: false,
                field: "Id",
                title: "Id",
                width: 50,
                editor: idEditor,
            }, {
                title: "Name",
                field: "Name",
                width: 100
            }, {
                command: ["edit", "destroy"],
                title: "&nbsp;",
                width: "250px"
            }]  

function idEditor(container, options) {
        container.append(options.model.Id);
    }