I want to use kendo grid sort mechanism, capture sort event and perform my own sorting on the server side. I dont' want the grid actually to perform the sorting (not on the client side nor on the server side).
I found that I can define my own sort function on the data source and catch the sort event as follows:
gridDatasource.originalSort = gridDatasource.sort;
gridDatasource.sort = function () {
if (arguments.length > 0) {
console.log("SORT: " + JSON.stringify(arguments));
}
//return gridDatasource.originalSort.apply(this, arguments);
}
That way I'm able to catch any sort operation before it happens but the problem is that if I don't call the original sort the triangle of the grid doesn't appear and the direction of the sort doesn't change. So any time I click the sort I get the same direction "asc".
Any other suggestions?
EDIT
below is more or less an example of the grid definitions:
var ds = new kendo.data.DataSource({});
ds.originalSort = ds.sort;
ds.sort = function () {
if (arguments.length > 0) {
console.log("SORT: " + JSON.stringify(arguments));
}
return ds.originalSort.apply(this, arguments);
}
$("#grid", element).kendoGrid({
dataSource: ds,
sortable: true,
pageable: true,
scrollable: {
virtual: true
},
filterable: true,
columns: [
{ field: "text", title: "text", hidden: false},
{ field: "id", title: "id", hidden: false},
{ field: "newColumn", title: "New column", hidden: false},
{ field: "anotherColumn", title: "Another column", hidden: false}
],
selectable: "row",
resizable: true,
columnMenu: true
});