julius_am
julius_am

Reputation: 1527

Using kendo grid sort mechanism with actually sorting

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

Upvotes: 1

Views: 1607

Answers (1)

Petur Subev
Petur Subev

Reputation: 20233

Set the dataSource to use serverSorting, use the parameterMap function to prepare the arguments in the format you want to send them to the server. And thus you become responsible to handle the sorting on the server side.

Upvotes: 1

Related Questions