【问题标题】:default sorting in kendo grid must be descending剑道网格中的默认排序必须是降序
【发布时间】:2016-09-30 07:12:50
【问题描述】:

我创建了一个剑道网格并使用 ajax 调用加载它的数据源。网格正在正确加载并且工作正常。现在我想仅基于一列对网格中的数据进行排序。网格定义如下:

$("#grid").kendoGrid({
    scrollable: true,
    resizable:true,
    filterable: {
        extra:false,
        operators: {
            string:{ contains: "Contains"}
        }
    },
    dataSource: {
        transport: {
            read: {
                url: urlStr + dataPrm,
                dataType: "json",
                async:true
            },
            parameterMap: function(data, type) {
                if (type == "read") {
                    return {
                        $start_rows: data.skip,
                        $page_size: data.pageSize
                    }
                }
            }
        },
        pageSize: 20,
        serverPaging : true,
        schema : {
            model: {
                fields: {
                    a_id  : { type: "string" },  
                    a_percentage: { type: "number" },
                    emp_last_name: { type: "string" },
                    emp_first_name : { type: "string" }
                }
            },
            data: function(response) {
                return response.GridResult;
            },
            total: function(response) {
                $("#totalRows").text(response.total);
                return response.total;
            }
        },
    }
    pageable: {
        pageSizes: true,
    },
    columns: [
        { field: "a_id",width:"17%",title: "A ID",headerTemplate: '<span title="A ID" style="font-weight: 300; color:#333">A ID</span>',template:"<a class='link' style='cursor:pointer'>#=a_id#</a>" },
        { field: "emp_last_name",width:"15%",title: "Last Name",template:"<span>#=emp_last_name#</span>",headerTemplate: '<span title="Employee" style="font-weight: 300; color:#333">Last Name</span>'},
        { field: "emp_first_name",width:"15%",title: "First Name",template:"<span>#=emp_first_name#</span>",headerTemplate: '<span title="Employee" style="font-weight: 300; color:#333">First Name</span>'},
        { field: "a_percentage", title: "percentage value",width:"15%",template: "#=getPercentage(a,a_percentage)#" }
    ]
});

如您所见,我已在其中使用 ajax 调用创建了网格。 当网格加载时,它必须是基于名为“a_percentage”的列的排序形式。 “a_percentage”列的值是使用名为“getPercentage”的方法评估的。 我已经在这个网格中实现了排序逻辑,但它限制用户点击可排序的列,即 a_percentage。 我不想通过单击此列对数据进行排序。 每当加载网格时,它必须根据“a_percentage”列按降序排序。 请帮助我如何实现此功能。

【问题讨论】:

    标签: kendo-grid


    【解决方案1】:

    可以配置 Grid 的 DataSource 对数据进行初始排序:

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-sort

    dataSource: {
        // ...
        sort: { field: "a_percentage", dir: "desc" }
        // ...
        serverPaging: true,
        serverSorting: true
    }
    

    请注意,所有数据操作都必须在客户端或服务器上执行。由于您使用的是服务器分页,所以还要将serverSortingserverFiltering 设置为true

    http://docs.telerik.com/kendo-ui/framework/datasource/overview#mixed-data-operations-mode

    【讨论】:

    • 感谢 dimodi,它对我帮助很大。
    猜你喜欢
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多