Skip to content

How to do custom sorting in svelte-headless-table? #198

Answered by Git002
Git002 asked this question in Q&A
Discussion options

You must be logged in to vote

Okay I figured it out. It was written in docs too but I wished there was a working example too, but I am greatful for the docs anyways. Leaving this, as it might be helpful to others too...

Here's how I did it for sorting dates well. You will have to modify the logic inside the compareFn yourself though according to your needs, the rest of the syntax will be the same.

table.column({
    header: tableHeaderKeys[key],
    accessor: key,
    plugins: {
        sort: {
            compareFn(left, right) {
                if (new Date(left) < new Date(right)) return -1;
                else if (new Date(left) > new Date(right)) return 1;
                else return 0;
            }
        }
 …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Git002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant