How to make Angular ui grid expand all rows initially?

℡╲_俬逩灬. 提交于 2019-12-05 02:59:41

In my case, the following worked:

    $scope.gridOptions = {
      ...
      onRegisterApi: function(gridApi) {
        $scope.gridApi = gridApi;
        $scope.gridApi.grid.registerDataChangeCallback(function() {
          $scope.gridApi.treeBase.expandAllRows();
        });
      }
    };

I find I can expand all rows by using rowsRendered event:

gridApi.core.on.rowsRendered(scope,() => {
        if (!gridApi.grid.expandable.expandedAll && !initialized)
        {
            gridApi.expandable.expandAllRows();
            initialized = true;
         }
});

I have used a variable initialized to identify if this is the first time rows are rendered as I only want to expand all rows initially.

None of the above worked for me for all of my grid use cases.

        $scope.gridApi.grid.registerDataChangeCallback(function() {
            if($scope.gridApi.grid.treeBase.tree instanceof Array){
                $scope.gridApi.treeBase.expandAllRows();
            }

        });

The following works in every case I have tested. DataChangeCallback is called twice (for some unknown reason) on initial page load. The first time, gridApi.grid.treeBase.tree is an object which causes the issue with gridApi.grid.treeBase.tree.forEach above:

None of these answers worked for me, the following did:

scope.gridApi.core.on.rowsRendered(null, () => {
    scope.gridApi.treeBase.expandAllRows();
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!