0

I have a ui-grid whose first column is:

  columnDefs : [$scope.getGroupIdColumn(),
                $scope.getKlasCodeColumn(),
                $scope.getKlasNummerColumn(),
                $scope.getNaamColumn()
            ]

where getGroupIdColumn is:

    $scope.getGroupIdColumn = function () {
        var result = new Object();
        result["name"] = 'GroupID';
        result["visible"] = false;
        result["type"] = 'number';
        if ($scope.groupingEnabled) {
            console.log("komt toch: " + $scope.speedDial.grouping);
            var grObj = new Object();
            grObj["groupPriority"] = 0;
            result["grouping"] = grObj;
            return result;
        }
        return result;
    }

Other column definitions are also like this.

If groupingEnabled is true, i have grouping. If false, without grouping. Until here, it works as excepted.

BUT

If i redefine that column, or even all the grid-options, it remains same as it is. Thus, if i have a grid with grouping and i redefine all grid options, i have still grid with grouping.

What should be done?

PS: gridApi.core.refresh(), $evalAsync().. are tried and no any improvement.

2 Answers 2

2

I just can't believe it was so easy! I'll write my functions which will be easier for people to get started: (also here is the documentation)

  1. Set gridApi in $scope:

    $scope.gridOptions.onRegisterApi = function (gridApi) {
        $scope.gridApi = gridApi;
    }
    
  2. Save your grouping info:

    $scope.groupInfo = $scope.gridApi.grouping.getGrouping();
    
  3. Just define these functions

    $scope.groupData = function () {
        if ($scope.groupInfo != undefined) {
            $scope.gridApi.grouping.setGrouping($scope.groupInfo);
        }
        setTimeout(function () {
            $scope.gridApi.treeBase.expandAllRows();
        }, 400);
        $scope.$evalAsync();
    }
    
    $scope.ungroupData = function () {
        // if ($scope.groupInfo != undefined) {
            // $scope.groupInfo = $scope.gridApi.grouping.getGrouping();
        // }
        $scope.gridApi.grouping.clearGrouping();
    }
    
Sign up to request clarification or add additional context in comments.

Comments

1

For my case I needed to toggle grouping and I tried your answer but it do not work for me so I changed it a bit.

$scope.groupData = function () {
    $scope.gridApi.grouping.groupColumn('columnName');
    $timeout(function(){
      $scope.gridApi.treeBase.expandAllRows();
    }, 300);
}

Working example http://plnkr.co/edit/AtcLSsqqnSaFeLfOEJhc?p=preview

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.