KendoUI网格/数据源中的自定义排序 [英] Custom Sorting in KendoUI grid/datasource
问题描述
我在dataSource中将数据分组为:
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" }
]
}
});
现在,我想根据此处指定的字段以外的其他字段对组进行排序.如何做到这一点?或者如何禁用或覆盖默认的"dir"升序排序行为.
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.
推荐答案
有一种未公开的方法来指定自定义排序函数,该函数将允许您对对象公开的任何一个或多个属性进行排序.
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
});
如果left小于right,则compare函数应返回一个负数;如果相等,则返回0;如果left大于right,则该函数应返回一个正数.
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.
这篇关于KendoUI网格/数据源中的自定义排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!