vincjo / datatables

A toolkit for creating datatable components with Svelte
https://vincjo.fr/datatables
MIT License
426 stars 14 forks source link

Filtering table columns and numbers #32

Closed silverliiv closed 1 year ago

silverliiv commented 1 year ago

Hey, first of all thanks for the great package, it has worked out great so far.

But I recently stumbled onto a smallish issue.

I have tables and columns with filtering, and filtering numbers does work from 1-9 but not if it gets higher. For example I have these data rows with values: AVG8, AVG10, AVG11

The filtering works like that: AVG8, AVG11, AVG10 OR AVG10, AVG11, AVG8

Meaning it's only taking into consideration the first part, not the whole number. I also attached some images to understand it better.

image image
riziles commented 1 year ago

@silverliiv , Is this a question about sorting or filtering?

silverliiv commented 1 year ago

I'm using this "Th" component (attached a screenshot).

image

I think it's sorting then yes, sorry for the mess.

vincjo commented 1 year ago

Hey,

Indeed, values ​​are sorted as strings, "8" > "11"

If it's possible you can cast these string values as numbers with a callback. it would look like this:

<Th 
    {handler} 
    orderBy={(row) => Number(row.avg_stack.replace('AVG', ''))}
>
    AVG Stack
</Th>
silverliiv commented 1 year ago

Perfect, solution worked nicely. Thank you.