首页 > 解决方案 > 如何将 selectAll 和 deSelectAll 应用于 ag-grid react 中的标题复选框

问题描述

我已将 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]);

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

在此处输入图像描述

提前致谢!

标签: reactjsreact-reduxag-gridag-grid-reactselectall

解决方案


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


推荐阅读