Skip to content

feat(table): include returning subrows when on expandable multiple mode #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/react/src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,10 @@ export const Table = <T extends object>({

useEffect(() => {
if (rowSelectionMode && onSelectedRowsChange) {
const selectedRowIds = currentRowSelection;
const selectedIndexes = Object.keys(selectedRowIds).filter((index) => selectedRowIds[index]);
const selectedRows = selectedIndexes.map((index) => data[parseInt(index, 10)]);
const selectedRows = Object.keys(currentRowSelection).map((rowId) => table.getRow(rowId).original);
onSelectedRowsChange(selectedRows);
}
}, [rowSelectionMode, currentRowSelection, onSelectedRowsChange, data]);
}, [rowSelectionMode, currentRowSelection, onSelectedRowsChange, table]);

return (
<StyledTable
Expand Down
49 changes: 49 additions & 0 deletions packages/storybook/stories/data-table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,55 @@ export const MultipleSelectableRows: Story = {
},
};

export const MultipleSelectableExpandableSubRows: Story = {
render() {
interface ExpandableData {
id: string;
name: string;
}

const columns: TableColumn<ExpandableData>[] = [
{
header: 'ID',
accessorKey: 'id',
},
{
header: 'Name',
accessorKey: 'name',
},
];

const data: TableData<ExpandableData>[] = [
{
id: '1',
name: 'AAA',
subRows: [
{ id: '1.A', name: 'AAA-1' },
{ id: '1.B', name: 'AAA-2' },
],
},
{
id: '2',
name: 'BBB',
subRows: [
{ id: '2.A', name: 'BBB-1' },
{ id: '2.B', name: 'BBB-2' },
],
},
];
return (
<Table
expandableRows="multiple"
rowSelectionMode="multiple"
columns={columns}
data={data}
onSelectedRowsChange={console.info}
expandChildsOnRowSelection
/>
);
},
};

export const SingleSelectableRows: Story = {
render() {
interface SelectableData {
Expand Down
Loading