剑道网格中的默认排序必须降序



我已经创建了一个剑道网格,并使用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"的列的排序形式。使用名为"getPercentage"的方法计算"a_percentage"列的值。我已经在这个网格中实现了排序逻辑,但它限制了用户单击可排序列,即a_percentage。我不想通过单击这一列来对数据进行排序。无论何时加载网格,都必须根据"a_percentage"列按降序对其进行排序。请告诉我如何才能实现这个功能。

可以配置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

最新更新