sort
Gets or sets the sort order which will be applied over the data items.
Parameters
value Object|Array
The sort configuration. Accepts the same values as the sort option.
Returns
Array
—The current sort configuration. Returns undefined
instead of an empty array if the DataSource instance has not performed any sorting so far.
Example - sort the data items
<script>
var dataSource = new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30 },
{ name: "John Doe", age: 33 }
]
});
dataSource.sort({ field: "age", dir: "desc" });
var view = dataSource.view();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(view[0].name); // displays "John Doe"
</script>
Example - get the sort configuration
<script>
var dataSource = new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30 },
{ name: "John Doe", age: 33 }
],
sort: { field: "age", dir: "desc" }
});
var sort = dataSource.sort();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(sort.length); // displays "1"
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(sort[0].field); // displays "age"
</script>