angularjs – 如何在角度ui.grid中找到已排序的列和按什么顺序排列

前端之家收集整理的这篇文章主要介绍了angularjs – 如何在角度ui.grid中找到已排序的列和按什么顺序排列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在角度ui.grid中找到已排序的列和按什么顺序排列.其实我想设置基于服务器的分页.为此,我将params中的数据发送为{pageNumber,pageSize,column,order}.现在如何找到用户已经排序的列(名称/年龄/数字)以及角度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相关文章