切换从反应表中的按钮组件中选择所有行

Biz*_*MAN 1 reactjs react-table

需要选择所有行而不使用表 API 中可用的复选框触发器。我想将此触发器放入一个单独的组件中,而不是文档中的组件,其中表列之一是全选触发器。

沙盒游乐场:https://codesandbox.io/s/test-select-all-button-toggle-33c3g ?file=/src/App.js

尝试检查文档https://react-table-omega.vercel.app/docs/api/useRowSelect#instance-properties上的选项可能是一个很好的指针,但我还没有弄清楚如何将其付诸实践。

并将其放入组件中,如下所示:

<IconHolder
  onClick={toggleAllRows} //trigger select all rows here
>
  <Text>
    <Icon
      actionIcon
      name={true ? "ok-circled2" : "circle-thin"}
      color={globalColors.purple}
      size={20}
    />{" "}
    Select All
  </Text>
</IconHolder>
Run Code Online (Sandbox Code Playgroud)

ber*_*ida 6

toggleAllRowsSelected从对象中使用table

toggleAllRowsSelectedFunction(?set: Bool) => void使用此函数可将所有行切换为选定或未选定。可选择传递truefalse将所有行设置为该状态

...

const {
  getTableProps,
  getTableBodyProps,
  headerGroups,
  rows,
  prepareRow,
  selectedFlatRows,
  state: { selectedRowPaths },
  toggleAllRowsSelected
} = table;


...
<button onClick={() => toggleAllRowsSelected()}>
  Select All Rows
</button>
Run Code Online (Sandbox Code Playgroud)

编辑测试选择所有按钮切换(分叉)