T
TanStack•17mo ago
adverse-sapphire

Global Filtering not working

Everything else is working...
const [globalFilter, setGlobalFilter] = useState("");
const [pagination, setPagination] = useState({
pageIndex: 0,
pageSize: 3,
});

useEffect(() => {
console.log("Global filter changed to:", globalFilter); // works
}, [globalFilter]);

const tableInstance = useReactTable({
columns,
data: sitemapUrls || [],
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onPaginationChange: setPagination,
getFilteredRowModel: getFilteredRowModel(),
onGlobalFilterChange: setGlobalFilter,
state: {
pagination,
globalFilter,
},
});
const [globalFilter, setGlobalFilter] = useState("");
const [pagination, setPagination] = useState({
pageIndex: 0,
pageSize: 3,
});

useEffect(() => {
console.log("Global filter changed to:", globalFilter); // works
}, [globalFilter]);

const tableInstance = useReactTable({
columns,
data: sitemapUrls || [],
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onPaginationChange: setPagination,
getFilteredRowModel: getFilteredRowModel(),
onGlobalFilterChange: setGlobalFilter,
state: {
pagination,
globalFilter,
},
});
22 Replies
adverse-sapphire
adverse-sapphireOP•17mo ago
This is my setup Everything appears to be working, but the data isnt getting filtered
flat-fuchsia
flat-fuchsia•17mo ago
maybe share a sandbox of this not working, because it mostly looks fine
adverse-sapphire
adverse-sapphireOP•17mo ago
https://codesandbox.io/p/sandbox/misty-architecture-qpdqqv?file=%2Fsrc%2FcolDefs.tsx%3A18%2C48 @KevinVandy hows this? haven't really created sandboxes like this before
flat-fuchsia
flat-fuchsia•17mo ago
There's some interesting things I see with your column defs and data, I guess in this sandbox the accessors don't access anything so the global filter has nothing to match with
adverse-sapphire
adverse-sapphireOP•17mo ago
accessors let me see oh i didn't send the data in but why does it paint the table? let me see if i made the same dumb mistake in my app no that seems to be the right pattern?
adverse-sapphire
adverse-sapphireOP•17mo ago
@KevinVandy how should the coldefs be? i usually only pass in handlers and things
No description
flat-fuchsia
flat-fuchsia•17mo ago
what does your data look like?
adverse-sapphire
adverse-sapphireOP•17mo ago
just a flat array in this case
flat-fuchsia
flat-fuchsia•17mo ago
an array of objects, right? not an array of strings like your sandbox?
adverse-sapphire
adverse-sapphireOP•17mo ago
No description
adverse-sapphire
adverse-sapphireOP•17mo ago
yes an array of strings it doesn't like that?
flat-fuchsia
flat-fuchsia•17mo ago
TanStack Table is designed to work with arrays of objects, not raw values
flat-fuchsia
flat-fuchsia•17mo ago
This is way more typical
No description
adverse-sapphire
adverse-sapphireOP•17mo ago
oh really? eh i havent had this problem yet this is like my 10th table and its rendering
flat-fuchsia
flat-fuchsia•17mo ago
The object could have just 1 key
adverse-sapphire
adverse-sapphireOP•17mo ago
ok ill transform it and see thank you!! <FilterTable data={[{ value: "a" }, { value: "c" }, { value: "b" }]} /> so if the data looks like this
flat-fuchsia
flat-fuchsia•17mo ago
then the accessorKey could be "value" and the global filter would be able to match that accessor
adverse-sapphire
adverse-sapphireOP•17mo ago
No description
adverse-sapphire
adverse-sapphireOP•17mo ago
works Damn
flat-fuchsia
flat-fuchsia•17mo ago
and set enableGlobalFilter: false for any columns that are not accessing values that you want to be scanned
adverse-sapphire
adverse-sapphireOP•17mo ago
What a waste of a day! Thank you @KevinVandy !! hmm ok i have to change my api 🤦 but good thank yo

Did you find this page helpful?