Clear grouping in ng-grid with external button

て烟熏妆下的殇ゞ 提交于 2019-12-08 13:35:03

问题


I have a ng-grid with data that is grouped by category, as shown below:

$scope.gridOptions = {
  columnDefs: [
    {field: 'cat', displayName: 'Category'},
    {field: 'name', displayName: 'Name'},
    {field: 'val', displayName: 'Value'}
  ],
  data: 'myData',
  groups: ['cat']
}

I would like to be able to un-group the data in the ng-grid externally with a button. I do not want to display the group panel (via $scope.gridOptions.showGroupPanel: true), which provides an 'X' to clear the grouping.

I have tried executing the following when clicking on the external button without any success:

  • $scope.gridOptions.groups = [];
  • $scope.gridOptions.groups.length = 0

Any suggestions on how I can clear the grouping? Ultimately I would like to be able to make the grouping toggle on/off with the button; however, clearing the grouping seems like a good first step. Thanks for your help!

Here is a Fiddle


回答1:


There is an undocumented function in the source code for programmatically setting groups. You can simply:

gridOptions.groupBy(columnFieldKey)

Unfortunately, I haven't been able to find a way to group by more than one column at a time, programmatically.




回答2:


You can add columns to the existing grouped column by a series of group by statements.

gridOptions.groupBy(col1);
gridOptions.groupBy(col2);

You can clear the existing group by

gridOptions.groupBy(null);


来源:https://stackoverflow.com/questions/20201924/clear-grouping-in-ng-grid-with-external-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!