-
In v7, we could add a custom component for filtering. How can we achieve this in v8? In v7:
CustomSelectFilter as:
CustomSelectColumnFilter as:
Is there any "complete" example? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
I found the answer thanks to other questions ... For a
with
and with
and inside the table:
|
Beta Was this translation helpful? Give feedback.
-
Struggled with this quite a bit too myself so here's a minimal example for using filterFn in case anyone stumbles onto this thread in the future. (esp. if you're looking for the custom filters to be outside the columns) Should be able to achieve something like this: Basically, these two pieces of code handles most of the heavy lifting:
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
table.getColumn("age")?.setFilterValue(e.target.checked);
};
filterFns: {
ageFilter: (row, columnId, filterValue) => {
return filterValue
? row.original[columnId] > 30
: row.original[columnId];
},
}, then, just make sure to apply the filter to the appropriate column: columnHelper.accessor("age", {
header: () => "Age",
cell: (info) => info.renderValue(),
filterFn: "ageFilter" as any, // add filter function here
}), |
Beta Was this translation helpful? Give feedback.
-
How to add custom data inside the ageFilter filterFn? ageFilter: (row, columnId, filterValue) => { But i need to do it on button press and by reading useState value |
Beta Was this translation helpful? Give feedback.
-
@zzincist many thanks for your explanation, only one question: |
Beta Was this translation helpful? Give feedback.
I found the answer thanks to other questions ...
For a
ColumnDef
:with
selectFilterFn
as:and with
CustomFilter