Custom Sorting in KendoUI grid/datasource

强颜欢笑 提交于 2019-12-11 03:09:03

问题


I have grouped data in dataSource as:

var dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      url: " ",

    }
  },
   //and some other parameters specified   
  // group by the "category" field
   group: {
    field: "category",
    aggregates: [
      { field: "price", aggregate: "max" },
      { field: "price", aggregate: "min" }
    ]
  }
});

Now i want to sort the group according to field other than the field specified here. How this could be achieved? Or how can i disable or override the default sorting behavior of "dir" as ascending.


回答1:


There is an undocumented way to specify a custom sort function which will allow you to sort on any property/properties exposed by your object.

$("#grid").kendoGrid({
    columns: [
        { 
            field: "someProperty",
            sortable: {
                compare: function (left, right) {
                    // TODO: your custom logic here (just make sure you return a number)
                    return left.someOtherProperty - right.someOtherProperty;
                }
            },
            title: "I can do custom sorting!!!"
    ],
    dataSource: { .. },
    // other grid properties here
});

The compare function should return a negative number if left is less than right, 0 if they are equal, and a positive number if left is greater than right.



来源:https://stackoverflow.com/questions/16571402/custom-sorting-in-kendoui-grid-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!