【问题标题】:How to disable sorting on columns when no records are available in kendo ui grid?当 kendo ui 网格中没有可用记录时,如何禁用对列的排序?
【发布时间】:2016-01-29 11:29:35
【问题描述】:

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

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

那该怎么做呢??

注意:我使用的是剑道 ui 脚本。

【问题讨论】:

    标签: kendo-ui telerik kendo-grid kendo-asp.net-mvc telerik-grid


    【解决方案1】:

    我们不能在 kendo Grid 运行时设置启用/禁用排序,但我们可以通过使用下面的代码 sn-p 间接实现这一点。

    <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>
    

    如果有任何问题,请告诉我。

    【讨论】:

    • 非常感谢您的回答,但我有 2 个网格。我的第一个网格中有记录,第二个网格中没有记录。所以我的排序现在不适用于我的第一个网格你的代码
    • 你太棒了。非常感谢。现在页面大小更改的点击事件相同吗?
    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2017-06-14
    • 2018-08-07
    相关资源
    最近更新 更多