我目前有一个Kendo-UI网格。它有几列可以供用户排序,非常好用。每一行还有一个详细信息链接,如果用户点击该链接,则会跳转到详细信息页面。我需要将当前排序作为值传递到详细信息页面。如何获取当前的排序?是否有我可以绑定的事件? 谢谢
我目前有一个Kendo-UI网格。它有几列可以供用户排序,非常好用。每一行还有一个详细信息链接,如果用户点击该链接,则会跳转到详细信息页面。我需要将当前排序作为值传递到详细信息页面。如何获取当前的排序?是否有我可以绑定的事件? 谢谢
例如:如果grid
是你的网格的id
,那么执行:
// 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");
}
click
事件处理程序内使用类似于grid.dataItem($(this).closest("tr"))
的方法来确定行,并使用dataSource.indexOf
找到对应项的索引。 - OnaBaidataBound
。 - OnaBai<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>
请参见:http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-sort