Kendo UI Grid Conditional editing

2020-02-13 05:21发布

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>

1条回答
手持菜刀,她持情操
2楼-- · 2020-02-13 06:04

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);
        }
    }
}
查看更多
登录 后发表回答