How can I select all the items in the table by different button? #638
-
I would like to have a button which when I click, all items in the table are selected. I see that onSelectionChange is only triggered when user manually select item in the table. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello! Note that the Table already provides a checkbox in the top left that allows your users to select and unselect all items in the table. The list of selected items is controlled by the For example: const [selectedItems, setSelectedItems] = useState([]);
return <>
<Button onClick={() => setSelectedItems(allItems)}>
Check all items in the table
</Button>
<Table
items={allItems}
selectedItems={selectedItems}
...
/>
</> You can find a running example of this in CodeSandbox. |
Beta Was this translation helpful? Give feedback.
Hello!
Note that the Table already provides a checkbox in the top left that allows your users to select and unselect all items in the table.
The list of selected items is controlled by the
selectedItems
property, which will be controlled by your application's state. You can select all items by passing all items into that property.For example:
You can find a running example of this in CodeSandbox.