|
| 1 | +import { Button, Container } from '@mantine/core'; |
| 2 | +import { |
| 3 | + MantineReactTable, useMantineReactTable |
| 4 | +} from '../../src'; |
| 5 | +import { type Meta } from '@storybook/react'; |
| 6 | + |
| 7 | +const meta: Meta = { |
| 8 | + title: 'Fixed Bugs/Custom Reset Button', |
| 9 | +}; |
| 10 | + |
| 11 | +export default meta; |
| 12 | + |
| 13 | +enum DataItemTypeEnum { |
| 14 | + Dog = 'Dog', |
| 15 | + Cat = 'Cat', |
| 16 | +} |
| 17 | + |
| 18 | +type DataItemType = { |
| 19 | + id: number; |
| 20 | + type: DataItemTypeEnum; |
| 21 | + sound: string; |
| 22 | +}; |
| 23 | + |
| 24 | +const typeOptions = [ |
| 25 | + { label: 'Cat', value: DataItemTypeEnum.Cat }, |
| 26 | + { label: 'Dog', value: DataItemTypeEnum.Dog }, |
| 27 | +]; |
| 28 | + |
| 29 | +const data: DataItemType[] = [ |
| 30 | + { |
| 31 | + id: 1, |
| 32 | + type: DataItemTypeEnum.Cat, |
| 33 | + sound: 'Meow', |
| 34 | + }, |
| 35 | + { |
| 36 | + id: 2, |
| 37 | + type: DataItemTypeEnum.Dog, |
| 38 | + sound: 'Arf', |
| 39 | + }, |
| 40 | +]; |
| 41 | + |
| 42 | +const CustomResetButton = () => { |
| 43 | + const table = useMantineReactTable({ |
| 44 | + data, |
| 45 | + enableRowActions: false, |
| 46 | + renderTopToolbar: false, |
| 47 | + enableBottomToolbar: false, |
| 48 | + enableColumnFilters: true, |
| 49 | + enableColumnActions: false, |
| 50 | + enableSorting: false, |
| 51 | + initialState: { |
| 52 | + showColumnFilters: true, |
| 53 | + }, |
| 54 | + columns: [ |
| 55 | + { |
| 56 | + accessorKey: 'id', |
| 57 | + header: 'ID', |
| 58 | + filterVariant: 'text', |
| 59 | + filterFn: 'contains', |
| 60 | + }, |
| 61 | + { |
| 62 | + accessorKey: 'type', |
| 63 | + header: 'Type', |
| 64 | + filterVariant: 'select', |
| 65 | + filterFn: 'equals', |
| 66 | + enableColumnFilter: true, |
| 67 | + mantineFilterSelectProps: { |
| 68 | + data: typeOptions, |
| 69 | + }, |
| 70 | + }, |
| 71 | + { |
| 72 | + accessorKey: 'sound', |
| 73 | + header: 'Sound', |
| 74 | + filterVariant: 'text', |
| 75 | + filterFn: 'contains', |
| 76 | + }, |
| 77 | + ], |
| 78 | + }); |
| 79 | + |
| 80 | + return ( |
| 81 | + <Container py="lg"> |
| 82 | + <Button mb="lg" onClick={() => table.resetColumnFilters()}> |
| 83 | + Custom Reset Button |
| 84 | + </Button> |
| 85 | + <MantineReactTable table={table} /> |
| 86 | + </Container> |
| 87 | + ); |
| 88 | +}; |
| 89 | + |
| 90 | +export { CustomResetButton }; |
0 commit comments