【问题标题】:Custom Sorting in KendoUI grid/datasourceKendoUI 网格/数据源中的自定义排序
【发布时间】:2013-05-15 17:28:17
【问题描述】:

我已将 dataSource 中的数据分组为:

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" }
    ]
  }
});

现在我想根据此处指定的字段以外的字段对组进行排序。这怎么可能实现?或者如何禁用或覆盖“dir”的默认排序行为为升序。

【问题讨论】:

  • 您必须在数据源上设置serverSorting: true 并在服务器上自行实现排序。

标签: kendo-ui kendo-grid


【解决方案1】:

有一种未记录的方式来指定自定义排序函数,它允许您对对象公开的任何属性进行排序。

$("#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
});

如果left小于right,compare函数应该返回一个负数,如果它们相等则返回0,如果left大于right,则返回一个正数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    相关资源
    最近更新 更多