Skip to content

Commit

Permalink
Add the SelectAll checkbox callback function for Batch actions carbon…
Browse files Browse the repository at this point in the history
  • Loading branch information
SeonyuK authored Feb 5, 2024
1 parent 95a4f59 commit 918026e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ return (
description: `When building a Datagrid that requires selectable rows, use the \`useSelectRows\` hook.
- Include \`useSelectRows\` hook
- Add \`onRowSelect\` to the \`useDatagrid\` hook, this is a callback function called when on a row's selection checkbox onChange, and sends back the row object and the event
- Add \`onAllRowSelect\` to the \`useDatagrid\` hook, this is a callback function called when on all rows selection checkbox onChange, and sends back all rows object and the event
`,
source: {
code: `
Expand All @@ -363,6 +364,7 @@ const datagridState = useDatagrid(
columns,
data,
onRowSelect: (row, event) => console.log(row, event),
onAllRowSelect: (rows, event) => console.log(rows, event),
batchActionMenuButtonLabel: 'More',
},
useSelectRows
Expand Down
5 changes: 5 additions & 0 deletions packages/ibm-products/src/components/Datagrid/Datagrid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,10 @@ hook.
2. Add `onRowSelect` to the `useDatagrid` hook, this is a callback function
called when on a row's selection checkbox onChange, and sends back the row
object and the event
3. Add `onAllRowSelect` to the `useDatagrid` hook, this is a callback function
called when on all rows selection checkbox onChange, and sends back all rows
object and the event


```jsx
const [data] = useState(makeData(10));
Expand All @@ -1199,6 +1203,7 @@ const datagridState = useDatagrid(
columns,
data,
onRowSelect: (row, event) => console.log(row, event),
onAllRowSelect: (rows, event) => console.log(rows, event),
},
useSelectRows
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ export const BatchActions = () => {
DatagridActions,
DatagridBatchActions,
rowActions: getRowActions(),
onSelectAllRows: () => console.log('onSelectAll batch action callback'),
onRowSelect: (row, event) => console.log('onRowClick: ', row, event),
onAllRowSelect: (rows, event) => console.log('onAllRowsClick called', rows, event),
batchActionMenuButtonLabel: 'More',
},
useSelectRows,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const SelectAll = (datagridState) => {
rows,
getRowId,
toggleAllRowsSelected,
onAllRowSelect,
} = datagridState;
const isFirstColumnStickyLeft =
columns[0]?.sticky === 'left' && withStickyColumn;
Expand Down Expand Up @@ -67,6 +68,8 @@ const SelectAll = (datagridState) => {
indeterminate: true,
});
toggleAllRowsSelected(false);
onAllRowSelect?.(rows, event);

return onChange?.({
target: { checked: false },
});
Expand All @@ -77,6 +80,7 @@ const SelectAll = (datagridState) => {
getRowId,
isChecked: event.target.checked,
});
onAllRowSelect?.(rows, event);
return onChange?.(event);
};

Expand Down

0 comments on commit 918026e

Please sign in to comment.