Repository navigation
Replies: 1 comment
|
In v8, For a predicate over the entire original object, a supported alternative is to filter the input array yourself and enable Inside your React component, using your existing import { useMemo, useState } from 'react';
import { getCoreRowModel, useReactTable } from '@tanstack/react-table';
const [globalFilter, setGlobalFilter] = useState('');
const filteredData = useMemo(() => {
const query = globalFilter.trim().toLowerCase();
if (!query) return data;
return data.filter((original) =>
Object.values(original).some((value) =>
String(value ?? '').toLowerCase().includes(query)
)
);
}, [data, globalFilter]);
const table = useReactTable({
data: filteredData,
columns,
getCoreRowModel: getCoreRowModel(),
manualFiltering: true,
state: { globalFilter },
onGlobalFilterChange: setGlobalFilter,
});Your search input can keep calling One tradeoff: The manual filtering guide documents the already-filtered-data contract. It doesn't require the filtering computation to run on a server. |
Uh oh!
There was an error while loading. Please reload this page.
Hi!
I have a list of objects with a lot of keys. Many of them are not relevant to show as columns, but I still want to use them when applying the global filter to filter the table.
I have created my own function for filtering but this function is called once per column. Is it possible to register a filter function that gets called once per row instead, or is there another way to go about it that I'm not seeing in the documentation?
My solution for now is that I set
enableGlobalFilter: falseon all columns except one, so that my filter function only gets called once per row. This is really hacky so I'm hoping there's a proper way to achieve this.All reactions