javascript - ag-grid - expandingcollapsing tree data - Stack Overflow

I'm using ag-grid (free) with Angular 1 and I've already gotten my tree data to display as de

I'm using ag-grid (free) with Angular 1 and I've already gotten my tree data to display as desired, where the children of a node are in the column to the right of it. However, what I want to do is collapse or expand nodes on double click. Right now just focusing on getting them to collapse since my default view is set to expand. here's my code for the double click event, given within $scope.gridOptions:

onCellDoubleClicked: function(event){ 
                                      event.node.expanded = false;
                                      $scope.gridOptions.api.refreshView();
                                     };

My assumption was that changing the expanded property to false would cause the refreshView call to re-render the grid with child nodes collapsed, but the view is unchanged after the double click.

Also, my getChildNodeDetails within gridOptions:

getNodeChildDetails: function(obj){
                if (obj.children){
                    var nodeType = obj.breakdownCol;
                    return {
                        group: true,
                        expanded: obj.expanded || true,
                        children: obj.children,
                        field: 'name',
                        key: obj[nodeType]
                    }
                } else {
                    return null;
                }
            }

Any ideas on how I might fix this without buying enterprise? I know that in enterprise you can group the rows and this es with build in expand/collapse functionality.

I'm using ag-grid (free) with Angular 1 and I've already gotten my tree data to display as desired, where the children of a node are in the column to the right of it. However, what I want to do is collapse or expand nodes on double click. Right now just focusing on getting them to collapse since my default view is set to expand. here's my code for the double click event, given within $scope.gridOptions:

onCellDoubleClicked: function(event){ 
                                      event.node.expanded = false;
                                      $scope.gridOptions.api.refreshView();
                                     };

My assumption was that changing the expanded property to false would cause the refreshView call to re-render the grid with child nodes collapsed, but the view is unchanged after the double click.

Also, my getChildNodeDetails within gridOptions:

getNodeChildDetails: function(obj){
                if (obj.children){
                    var nodeType = obj.breakdownCol;
                    return {
                        group: true,
                        expanded: obj.expanded || true,
                        children: obj.children,
                        field: 'name',
                        key: obj[nodeType]
                    }
                } else {
                    return null;
                }
            }

Any ideas on how I might fix this without buying enterprise? I know that in enterprise you can group the rows and this es with build in expand/collapse functionality.

Share Improve this question edited Oct 24, 2016 at 17:56 Jarod Moser 7,3582 gold badges28 silver badges55 bronze badges asked Oct 24, 2016 at 14:08 withoutdistractionwithoutdistraction 511 gold badge1 silver badge4 bronze badges 2
  • I assume you are trying to recreate row grouping (example) rather than column grouping (example) correct?... since column grouping is a part of the free version... – Jarod Moser Commented Oct 24, 2016 at 17:24
  • @JarodMoser Correct, should work like the expanding/collapsing you see in that row grouping example. – withoutdistraction Commented Oct 24, 2016 at 17:55
Add a ment  | 

2 Answers 2

Reset to default 2

In my own application I created a work around that simulates the row grouping feature. What it really does is adds and removes the data from the grid.

One drawback that this option has is that since the rows aren't actually in the table any filtering or sorting on columns can't actually take place on data that isn't shown, unlike the actual enterprise feature that the grid offers. However if you have disabled filtering and sorting then this option is perfectly viable.

Something like this:

function toggleExpansion(index, data) {
    if (insert) {
        gridOptions.api.insertItemsAtIndex(index, data);
    } else {
        gridOptions.api.removeItems(data)
    }
}

My specific code goes into more checks and other things unrelated to this question but that is the simple explanation of what I am doing as a work around.

I am using React, but you could probably do something similar with Angular:

function expandAll(expand) {
  agGridRef.current.api.forEachNode((node) => {
    node.setExpanded(expand);
  });
}

where the agGridRef is a reference to the ponent:

<AgGridReact
  ref={agGridRef}
.
.
.
</AgGridReact>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742322032a4422005.html

相关推荐

  • javascript - ag-grid - expandingcollapsing tree data - Stack Overflow

    I'm using ag-grid (free) with Angular 1 and I've already gotten my tree data to display as de

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信