【问题标题】:ag-grid setColumnVisible can't show/hide row group columns?ag-grid setColumnVisible 无法显示/隐藏行组列?
【发布时间】:2021-12-21 23:36:35
【问题描述】:

无法确定 ag-grid 是否具有该功能,因此尝试模拟类似于 Tableau 报表如何隐藏或显示下一个分组列,具体取决于前一个列行组是否展开。我有列定义来切换行分组,以及它们链接的列组的其余部分,如下所示:

colDefs = [
{ showRowGroup: 'col_A', cellRenderer: 'agGroupCellRenderer', headerName: 'Column A', hide: false },
{ showRowGroup: 'col_B', cellRenderer: 'agGroupCellRenderer', headerName: 'Column B', hide: true },
{ showRowGroup: 'col_C', cellRenderer: 'agGroupCellRenderer', headerName: 'Column C', hide: true },
{ headerName: 'Column A', field: 'col_A', rowGroup: true, hide: true },
{ headerName: 'Column B', field: 'col_B', rowGroup: true, hide: true },
{ headerName: 'Column C', field: 'col_C', rowGroup: true, hide: true },
{ headerName: 'Column D', field: 'col_D', hide: false },
];

A、B 和 C 列可以展开以显示子行。定义显示,首先仅显示第一组列 A 列,旁边是详细数据(其中我有一个渲染器来显示总和)。

我在网格选项中设置了 onRowGroupOpened 来检测行组的打开和折叠,我想在展开时分别显示 B 列和 C 列,所以我使用了 setColumnVisible,但传递了列对象或键(例如as 'col_B') 将导致具有字段:'col_B' 的非组列显示 (colDef[4]) 而不是 agGroupCellRenderer 列 def (colDef[1])。

如果可以通过索引而不是字段名称设置可见性,问题将得到解决。

正在尝试寻找解决方法,感谢任何帮助。

【问题讨论】:

    标签: ag-grid ag-grid-angular


    【解决方案1】:

    在我发布问题后不久就找到了解决方案。

    setColumnVisible 指的是要显示/隐藏的列的“colId”属性,它会自动设置为普通列的字段名称,但对于行组列,它被设置为字符串数字 - “0”、“1”、“2”。能够使用它们作为显示和隐藏列的键。

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2020-05-01
      相关资源
      最近更新 更多