如何在 angular ui.grid 中找到哪一列被排序以及以什么顺序排序。其实我想设置基于服务器的分页。为此,我将参数中的数据作为 {pageNumber, pageSize, column, order} 发送。现在如何在 angular ui.grid 中查找用户已排序的列(姓名/年龄/数字)以及排序顺序(ASC/DESC)
最佳答案
对列进行排序后,Angular ui-grid 会启动 sortChanged 事件。
您还必须将 useExternalSorting
显式设置为 true。
您可以在 onRegisterApi
函数的 gridOptions 中捕获此事件,并在回调函数中处理排序逻辑,该函数将网格和已排序列的数组作为参数,如下所示:
$scope.gridOptions = {
useExternalSorting: true,
columnDefs: [
...
],
onRegisterApi: function( gridApi ) {
$scope.gridApi = gridApi;
$scope.gridApi.core.on.sortChanged( $scope, function(grid, sortColumns){
// sortColumns is an array containing just the column sorted in the grid
var name = sortColumns[0].name; // the name of the first column sorted
var direction = sortColumns[0].sort.direction // the direction of the first column sorted: "desc" or "asc"
// Your logic to do the server sorting
});
}
};
关于angularjs - 如何在angular ui.grid中查找哪一列被排序以及以什么顺序排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32740307/