Ng-grid access to sorted array data

I need to access an array of sorted data after sorting a table, since the original value has not changed.

Exists gridOptions.ngGrid.filteredDatabut notgridOptions.ngGrid.sortedData

How can I access a sorted array?

+4
source share
1 answer

Instead of just changing the look of the data in the grid, you can resort to the & hellip; if you use Underscore.js , you can add a function and change headerCellTemplateas shown below.

Modified by 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>

New Feature:

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

, , , ng-click col.sort($event) mySort(col.displayName)

+1

Source: https://habr.com/ru/post/1532042/


All Articles