Skip to content

Commit 4b20b52

Browse files
committed
fix: handle select reset correctly
1 parent 23580b7 commit 4b20b52

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

packages/mantine-react-table/src/components/inputs/MRT_FilterTextInput.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ export const MRT_FilterTextInput = <TData extends MRT_RowData>({
199199
newFilterValues[rangeFilterIndex as number] = undefined;
200200
return newFilterValues;
201201
});
202+
// This is from Mantine v6 but it also applies for v7
203+
// https://github.com/mantinedev/mantine/issues/4716#issuecomment-1702699688
204+
} else if (isSelectFilter) {
205+
setFilterValue(null);
206+
column.setFilterValue(null);
202207
} else {
203208
setFilterValue('');
204209
column.setFilterValue(undefined);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)