Is it possible to filter one column by multiple values #2247
-
Unfortunately, i can't find a way to filter column by setting multiple values. For example, I have a column where I have rows with such values: 'on progress', 'hold', 'unrated', 'done' and I want to see only rows where I have values 'on progress' and 'done'. How can I do it? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 18 replies
-
You can write your own custom filter function |
Beta Was this translation helpful? Give feedback.
-
Also, I can't add filter by setting setAllFilters, maybe someone has a working example |
Beta Was this translation helpful? Give feedback.
-
iconicbrew, thanks for your post; it was helpful. I've had a lot of trouble figuring this out, so maybe I can help clarify for others. I'm using
When I call setFilter, I'm passing the accessor and the values I want to filter. Here is a hardcoded example: In
Lastly, my custom filter which is mostly from the previous post. Since I'm using columnIds in the filter, it should work for my other fields as well.
|
Beta Was this translation helpful? Give feedback.
-
With Typescript export function multiSelectFilter<T extends object>(
rows: Row<T>[],
columnId: keyof T,
filterValue: string[]
) {
return filterValue.length === 0
? rows
: rows.filter((row) =>
filterValue.includes(String(row.original[columnId]))
);
} Usage {
id: "price",
Header: "Price",
accessor: "price",
filter: multiSelectFilter,
}, |
Beta Was this translation helpful? Give feedback.
-
I hope it serves |
Beta Was this translation helpful? Give feedback.
You can write your own custom filter function