kendo ui 网格中没有可用记录时如何禁用列排序?

How to disable sorting on columns when no records are available in kendo ui grid?

我正在使用 Kendo ui 网格:http://demos.telerik.com/kendo-ui/grid/index

我正在做服务器端排序,现在我想要的是当“没有可用记录”时,我想禁用对某些列的排序。

那么怎么做呢??

注意:我正在为 kendo ui 使用脚本。

我们无法在 kendo 网格中设置 enable/disable 排序在 运行 时间,但我们可以使用下面的代码片段间接实现这一点。

<body>
    <div id="grid"></div>
    <script src="http://demos.telerik.com/kendo-ui/content/shared/js/products.js"></script>
    <script>
        $(document).ready(function () {
            //To test your requirement please remove comment from below code line
            //products = null;
            $("#grid").kendoGrid({
                dataSource: {
                    data: products,
                    schema: {
                        model: {
                            fields: {
                                ProductName: { type: "string" },
                                UnitPrice: { type: "number" },
                                UnitsInStock: { type: "number" },
                                Discontinued: { type: "boolean" }
                            }
                        }
                    }
                },
                height: 550,
                groupable: true,
                sortable: true,
                columns: [
                            "ProductName",
                            { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "130px" },
                            { field: "UnitsInStock", title: "Units In Stock", width: "130px" },
                            { field: "Discontinued", width: "130px" }
                ]
            });
            $("#grid .k-grid-header .k-link").click(function (e) { 
                if ($("#grid").data("kendoGrid").dataSource.data().length == 0) {
                    e.stopPropagation();
                }
            });
        });
    </script>
</body>

如有任何疑问,请告诉我。