问题
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