shagrin shagrin - 2 months ago 34
Javascript Question

Ng-Grid will collapse rows after data refresh, how to prevent that?

I am using Ng-Grid with grouping option, where groups are collapsed by default.
Each row of data has a link to perform some operation on it. After operation is done, grid should refresh data. This part works fine.

The problem is with aggregation: after data refresh, all rows get collapsed. This is really annoying.

Is there any possibility to expand specific group after data refresh?
I tried:

$scope.gridOptions.ngGrid.rowFactory.aggCache[$scope.expandedGroupID].toggleExpand();


and

$scope.gridOptions.ngGrid.rowFactory.aggCache[$scope.expandedGroupID].collapsed=false;


But that didn't work.

Example Plunker with grid configuuration can be found here

Answer

If anyone struggles with the same problem, here is how I fixed that:

$scope.$on('ngGridEventData', function () {
    $scope.availableGroupsOptions.ngGrid.rowFactory.aggCache[idx].toggleExpand();      
});

The key is 'ngGridEventData'.