Skip to content

Commit

Permalink
bug: add example bug with col grouping feat
Browse files Browse the repository at this point in the history
  • Loading branch information
dangkhoa99 committed Sep 10, 2024
1 parent 743e376 commit 3d064ef
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {
type MRT_Column,
type MRT_ColumnDef,
MaterialReactTable,
useMaterialReactTable,
} from '../../src';
import { faker } from '@faker-js/faker';
import { type Meta } from '@storybook/react';
import { Button } from '@mui/material';

const meta: Meta = {
title: 'Features/Column Grouping Examples',
Expand Down Expand Up @@ -360,3 +362,59 @@ export const GroupingAndDraggingWithSomeDisabledGrouping = () => {
/>
);
};

export const GroupingBug = () => {
const [open, setOpen] = useState(false);

return (
<>
<Button
onClick={() => {
setOpen(!open);
}}
>
Toggle
</Button>

{open && <GroupingTableBug />}
</>
);
};

const GroupingTableBug = () => {
const columns = useMemo<MRT_ColumnDef<Person>[]>(
() => [
{
accessorKey: 'firstName',
enableGrouping: false,
header: 'First Name',
},
{
accessorKey: 'lastName',
header: 'Last Name',
},
],
[],
);

const rowCount = useMemo(() => data.length ?? 0, [data.length]);

const table = useMaterialReactTable({
rowCount,
enableRowVirtualization: true,
columns,
data,
enableGrouping: true,
groupedColumnMode: 'remove',
enablePagination: false,
initialState: { expanded: true },
state: { grouping: ['firstName'] },

// Bug when set `enableTopToolbar: false`
enableTopToolbar: false,
});

console.log('[table] rowModel', table.getRowModel());

return <MaterialReactTable table={table} />;
};

0 comments on commit 3d064ef

Please sign in to comment.