Kendo UI网格条件编辑

Kendo UI网格条件编辑

问题描述:

我想为某些CatalogProductId禁用DiscountPercentageMRC/NRC/Usage列.请在下面的javascript表格中查找.任何帮助将不胜感激.

I would like to disable DiscountPercentageMRC/NRC/Usage columns for certain CatalogProductId's. Please find below javascript for the grid. Any help would be greatly appreciated.

<h2>Kendo Grid bound to ASP.NET MVC action methods</h2>
@* The DIV where the Kendo grid will be initialized *@
<div id="grid"></div>
<script>
  $(document).ready(function () {
     $("#grid").kendoGrid({
         columns: [
         { field: "CompanyId"},
         { field: "CompanyName" },
         { field: "DiscountPercentageMRC" },
         { field: "CatalogProductId"},
         { field: "DiscountPercentageMRC" },
         { field: "DiscountPercentageNRC" },
         { field: "DiscountPercentageNRC" },
         { field: "DiscountPercentageUsage"}
         ],
        height: 400,
        editable: true, // enable editing
        pageable: true,
        sortable: true,
        filterable: true,
        toolbar: ["create", "save", "cancel","edit"], // specify toolbar commands
        dataSource: {
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true,
            pageSize: 10,
            batch: true, 
            editable: "inline",
            transport: {
                read: {
                    url: "@Url.Action("ResellerDiscountsGet", "AccountDetail", new {                     BusOrdId = @ViewBag.Message })",
                    type: "POST",

                }
            }
        },

        selectable: true
    });

     });

   </script>

您将使用Edit事件启用/禁用单元格.我在这里创建了一个工作示例: http://jsfiddle.net/Eh8GL/151/

You would use the Edit event to enable/disable cells. I created a working example here: http://jsfiddle.net/Eh8GL/151/

function OnEdit(e) {
    // Make sure it's not a new entry
    if (!e.model.isNew()) {
        var catalogproductid =  e.container.find("input[name=CatalogProductId]").data("kendoNumericTextBox").value();

        // Disable DiscountPercentageMRC if catalog productid = 100
        if (catalogproductid == 100) {
            var disableField = e.container.find("input[name=DiscountPercentageMRC]").data("kendoNumericTextBox");
            disableField.enable(false);
        }
    }
}