T
TanStack2y ago
fair-rose

Check if column exists to render filter

Hello. In my custom table i have some quick filters in the table's toolbar. To show the i have something like this:
table.getColumn('status') && <TableStatusFilter/>
table.getColumn('status') && <TableStatusFilter/>
The problem in this is that in my console, i receiver this error when column doesn't exist. " [Table] Column with id 'status' does not exist." How to handle this or how to check correctly if a column exists without triggering an error?
3 Replies
grumpy-cyan
grumpy-cyan2y ago
Does it actually fail, or just write to the console? It looks like that error is only written in dev mode (https://github.com/TanStack/table/blob/main/packages/table-core/src/core/table.ts#L508). You may be able to ignore it. If not, you could probably get all the flat columns yourself and then do more or less what _getAllFlatColumnsById does in that module.
optimistic-gold
optimistic-gold17mo ago
We actually used to throw an error here in earlier versions. This API was designed to work assuming the column does indeed exist
fair-rose
fair-roseOP17mo ago
Yes but I use the same data table component for different kind of data and I show the quick filter (status for example) if a column with this name exists. It’s very annoying seeing all these errors even in dev mode. I was wondering if it’s another way of doing it using the table API.

Did you find this page helpful?