T
TanStack4mo ago
rare-sapphire

Filter columns based on the value of a formatted cell.

Hey all, using shadcn table for a side project. Having some trouble with filtering a column that has been formatted as the value within in each cell is pretty different from the default. Is there a property im missing here? I would ideally like to filter based off the formatted value and not the original.
1 Reply
mute-gold
mute-gold4mo ago
Hi! What kind of data is it that you want to filter, and how does it look before and after formatting? Generally, i think it is good to delay formatting as late as possible, since filterFns, sortingFns usually need pure values to work properly. For example a column of date, the accessorFn should return either an isoDate, a Date object or any other date format that is in some kind of pure form. Then you can create your sortingFns and filterFns to accept this date of the pure form, and use date comparisons etc. The visual representation of the date might be e.g translated into a internationalization function, based on the given user preferences, and also maybe formatted in some way. Sorting and filtering is much harder to do when the data in accessorFn is already translated or formatted, since it would require you to format-back every value in that column to a Date object or dateString that you can actually compare values with. In short, it is much harder to sort and filter "Mon 5. July 2023" vs "2023-07-05T00:00:00.000Z"

Did you find this page helpful?