user2206329
user2206329

Reputation: 2842

How to get kendo ui grid sort event?

I currently have a Kendo-UI grid. It has a few column where user can sort on, works great. I also have a details link on each row, so if the user clicks on this they are taken to a details page. I need to pass the current sort into the details page as a value. How can I get the current sort? is there an event I can bind to? Thanks

Upvotes: 7

Views: 14833

Answers (2)

Brian Edwards
Brian Edwards

Reputation: 423

I ran into this need today and learned that the event is now present as of 2016 R3 release (2016.3.914).

Example usage:

<div id="grid"></div>
<script>
  $("#grid").kendoGrid({
    columns: [
      { field: "name" },
      { field: "age" }
 ],
dataSource: {
  data: [
        { id: 1, name: "Jane Doe", age: 30 },
        { id: 2, name: "John Doe", age: 33 }
     ],
     schema: {
       model: { id: "id" }
     }
   },
   sortable: true,
    sort: function(e) {
      console.log(e.sort.field);
      console.log(e.sort.dir);
    }
  });
</script>

See: http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-sort

Upvotes: 1

OnaBai
OnaBai

Reputation: 40887

You can get the sorting configuration whenever you want using sort method.

Example: Being grid the id of your Grid. Do:

// Get the grid object
var grid = $("#grid").data("kendoGrid");
// Get the datasource bound to the grid
var ds = grid.dataSource;
// Get current sorting
var sort = ds.sort();
// Display sorting fields and direction
if (sort) {
    for (var i = 0; i < sort.length; i++) {
        alert ("Field:" + sort[i].field + " direction:" + sort[i].dir);
    }
} else {
    alert("no sorting");
}

Upvotes: 12

Related Questions