Custom column filter #13
-
I'd like to implement a custom date range filter for a column. Is there a way to hook up a custom component? |
Beta Was this translation helpful? Give feedback.
Answered by
KevinVandy
Jul 1, 2022
Replies: 1 comment 2 replies
-
You can pass in a custom Filter component on a column definition. I have this example in the storybook from a while ago for a custom select https://www.material-react-table.dev/?path=/story/features-filtering-examples--custom-filter-component const columns={[
{
header: 'First Name',
id: 'firstName',
},
{
header: 'Last Name',
id: 'lastName',
},
{
header: 'Age',
id: 'age',
},
{
header: 'Gender',
id: 'gender',
Filter: ({ header }) => (
<TextField
onChange={(e) =>
header.column.setFilterValue(e.target.value || undefined)
}
select
value={header.column.getFilterValue() ?? ''}
margin="dense"
placeholder="Filter"
variant="standard"
fullWidth
>
<MenuItem value={null}>All</MenuItem>
<MenuItem value="Male">Male</MenuItem>
<MenuItem value="Female">Female</MenuItem>
<MenuItem value="Other">Other</MenuItem>
</TextField>
),
filterFn: (row, _columnId, filterValue) =>
row.getValue('gender').toLowerCase() === filterValue.toLowerCase(),
},
{
header: 'Address',
id: 'address',
},
{
header: 'State',
id: 'state',
},
]} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
KevinVandy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass in a custom Filter component on a column definition. I have this example in the storybook from a while ago for a custom select https://www.material-react-table.dev/?path=/story/features-filtering-examples--custom-filter-component