2013-05-15 26 views
2

我已经在数据源分组数据:自定义排序在KendoUI网/数据源

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”的默认排序行为作为升序。

+0

您必须在数据源上设置'serverSorting:true'并在服务器上实现自己的排序。 – Brett

回答

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

比较功能应该返回一个负数小于右边,0,如果他们是平等的,如果离开了正数大于右更大。