加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – ng-grid访问已排序的数组数据

发布时间:2020-12-17 16:58:14 所属栏目:安全 来源:网络整理
导读:因为原始文件未更改,所以我需要在排序表后访问排序数据数组. 有一个gridOptions.ngGrid.filteredData但没有gridOptions.ngGrid.sortedData 如何访问已排序的数组? 解决方法 您可以使用 Underscore.js,而不仅仅是更改网格中数据的外观……如果使用 Underscor
因为原始文件未更改,所以我需要在排序表后访问排序数据数组.

有一个gridOptions.ngGrid.filteredData但没有gridOptions.ngGrid.sortedData

如何访问已排序的数组?

解决方法

您可以使用 Underscore.js,而不仅仅是更改网格中数据的外观……如果使用 Underscore.js,则可以添加函数并修改headerCellTemplate,如下所示.

修改headerCellTemplate:

<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{'cursor': col.cursor}" ng-class="{ 'ngSorted': !noSortVisible }">
  <div ng-click="mySort(col.displayName)" ng-class="'colt' + col.index" class="ngHeaderText">{{col.displayName}}</div>
  <div class="ngSortButtonDown" ng-show="col.showSortButtonDown()"></div>
  <div class="ngSortButtonUp" ng-show="col.showSortButtonUp()"></div>
  <div class="ngSortPriority">{{col.sortPriority}}</div>
  <div ng-class="{ ngPinnedIcon: col.pinned,ngUnPinnedIcon: !col.pinned }" ng-click="togglePin(col)" ng-show="col.pinnable"></div>
</div>
<div ng-show="col.resizable" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event)"></div>

新功能:

$scope.mySort = function (field) {
  $scope.gridOptions.data = _.sortBy($scope.gridOptions.data,function (item) {return item.field});
};

我对默认模板所做的唯一更改是在第二行,我将ng-click的值从col.sort($event)更改为mySort(col.displayName)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读