ui icon indicating copy to clipboard operation
ui copied to clipboard

Data Table - Filter by number not working

Open donhook opened this issue 1 year ago • 4 comments

I am using the data table with filters on columns. The filters for string valued columns work great, but a filter on a number column does not.

What is the best way to get around this?

Thx

donhook avatar Dec 12 '23 17:12 donhook

Hey did you find any solution?

Sattu2806 avatar Dec 19 '23 13:12 Sattu2806

No, i did not... if i dont find one soon, I will be switching to a different UI solution

donhook avatar Dec 19 '23 13:12 donhook

Hey I got a solution, just make your data type to string using accessorFn in columns.

But there is catch, now that I have changed my data to string if i search by number 1 then I will get all the values from that column which has 1 in it So, I think this could be temporary solution as I did not find any solution on filtering integer data.

You can learn some more here: https://github.com/TanStack/table/issues/4210

Hope this helps

Here is what I did:

Screenshot 2023-12-19 at 7 47 56 PM Screenshot 2023-12-19 at 7 48 33 PM

Sattu2806 avatar Dec 19 '23 14:12 Sattu2806

filterFn: (row, columnId, filterValue: string) => {
      const search = filterValue.toLowerCase();
      let value = row.getValue(columnId) as string;
      if (typeof value === "number") value = String(value);
      return value?.toLowerCase().includes(search);
},

for column def

lucasli0721 avatar Jan 10 '24 15:01 lucasli0721

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 11 '24 23:02 shadcn