如何过滤 AG 网格中选定的行并使其保持选定状态?

发布于 2025-01-11 19:04:51 字数 263 浏览 1 评论 0原文

我想根据复选框选择来过滤 AG 网格行,并且希望将它们保持为选中状态。

我知道使用下面的方法我可以过滤选定的行,但过滤后行将失去其选定状态。

gridOptions.api.setRowData(gridOptions.api.getSelectedRows())

我可以运行 gridoptions.api.selectAll() 但我必须避免它,因为我不希望触发 AG 网格选择更改事件。

任何想法我怎样才能实现它?

I want to filter my AG grid rows based on checkbox selection and I want to keep them as selected.

I know using below method I can filter selected rows but after filtering the rows are losing its selected state.

gridOptions.api.setRowData(gridOptions.api.getSelectedRows())

I can run gridoptions.api.selectAll() but I have to avoid it as I don't want AG grid selection change event to be triggered.

Any Idea how can I achieve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚你发端 2025-01-18 19:04:51

使用 ag-grid filter external 手动过滤列。在行定义中将行过滤器设置为 true。
覆盖 ag-grid 中的 isExternalFilterPresent 和 doesExternalFilterPass 方法
在 HTML 中

  <ag-grid-angular
  [columnDefs]="columnDefs"
  [isExternalFilterPresent]="isExternalFilterPresent"
  [doesExternalFilterPass]="doesExternalFilterPass"
  [rowData]="rowData"
  (gridReady)="onGridReady($event)"
></ag-grid-angular>

.ts 中定义在组件外部(或静态)

// Used in isExternalFilterPresent() to detect if (external)filter is active or not
let Gobal_filterSelectedDocuments: boolean;

和组件中

onToggleDocumentsFilterClick(event: MatSlideToggleChange) {
    Gobal_filterSelectedDocuments = event.checked;
    // nesseary notification to enable the filter
    this.gridApiObjects.onFilterChanged()
}

isExternalFilterPresent() {
    // Here we have no access to the 'this.' of the component. Use a Global Variable instedt.
    return Gobal_filterSelectedDocuments;
}

doesExternalFilterPass(node) {
    // Show only selected nodes
    return node.isSelected();
}

最大的问题是 isExternalFilterPresent() 具有不同的作用域和 this.是一个角度对象(gridapi?)不是当前组件。所以我需要一个全局/静态变量来解决这个问题。

Use ag-grid filter external to filter columns by hand. In the rowdefintion set the filter for the rows to true.
Override the methods isExternalFilterPresent and doesExternalFilterPass from ag-grid
in HTML

  <ag-grid-angular
  [columnDefs]="columnDefs"
  [isExternalFilterPresent]="isExternalFilterPresent"
  [doesExternalFilterPass]="doesExternalFilterPass"
  [rowData]="rowData"
  (gridReady)="onGridReady($event)"
></ag-grid-angular>

in .ts define outside of your component (or do it static)

// Used in isExternalFilterPresent() to detect if (external)filter is active or not
let Gobal_filterSelectedDocuments: boolean;

and in your component

onToggleDocumentsFilterClick(event: MatSlideToggleChange) {
    Gobal_filterSelectedDocuments = event.checked;
    // nesseary notification to enable the filter
    this.gridApiObjects.onFilterChanged()
}

isExternalFilterPresent() {
    // Here we have no access to the 'this.' of the component. Use a Global Variable instedt.
    return Gobal_filterSelectedDocuments;
}

doesExternalFilterPass(node) {
    // Show only selected nodes
    return node.isSelected();
}

The biggest issue is that the isExternalFilterPresent() has a differnt scope and the this. is an angular object (gridapi?) not the current component. So i needed a gobal/static variable to work around this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文