如何将 selectAll 和 deSelectAll 应用于 ag-grid react 中的标题复选框

Posted

技术标签:

【中文标题】如何将 selectAll 和 deSelectAll 应用于 ag-grid react 中的标题复选框【英文标题】:how to apply selectAll and deSelectAll to the header checkbox in ag-grid react 【发布时间】:2021-06-18 13:26:21 【问题描述】:

我已将 checkboxSelection 添加到我的第一列以及 headerCheckBoxSelection。

columnDefs: [
  
    minWidth: 45,
    maxWidth: 45,
    headerCheckboxSelection: true,
    checkboxSelection: true,
    lockPosition: true,
    hide: selectedHeaders.length === 0 ? true : selectedHeaders.includes('Name')
  ,

但是 select 和 deseltall 的标题复选框不起作用。 我为 selectAll 和 deselectAll 添加了两个回调,但我不确定在哪里添加这些回调,以便我可以选择和取消选择所有行:

const deselectAllHandler = useCallback(() => 
 gridApi.deselectAll();
, [gridApi]);

const selectAllHandler = useCallback(() => 
 gridApi.selectAll();
, [gridApi]);

我可以选择单个复选框并检索所选行,但无法全选和取消全选

提前致谢!

【问题讨论】:

【参考方案1】:

抱歉,我一直使用的 Grid 组件是一个共享组件,有人在该复选框上禁用了鼠标单击。 所以,这个属性 headerCheckboxSelection: true 足以允许全选和取消全选。

【讨论】:

以上是关于如何将 selectAll 和 deSelectAll 应用于 ag-grid react 中的标题复选框的主要内容,如果未能解决你的问题,请参考以下文章