Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Re-apply current sorting upon data change #27

Closed
MattPurland opened this issue May 5, 2021 · 1 comment
Closed

Re-apply current sorting upon data change #27

MattPurland opened this issue May 5, 2021 · 1 comment

Comments

@MattPurland
Copy link

MattPurland commented May 5, 2021

Is it possible to re-apply any column sorting applied should the underlying data be changed? I'm applying custom filtering to the bound data which is returned via ajax. The returned data isn't necessarily ordered as per the applied column sorting.

@MattPurland
Copy link
Author

I've found a workaround:

import { columns } from "svelte-simple-datatables/src/stores/columns.js";
import { data } from 'svelte-simple-datatables/src/stores/data.js'

...

function sortTable() {
    // Filter to get current column used for sorting
    let sortColumn = columns.get().find(column => column.classList.contains('asc') || column.classList.contains('desc'));

    // Sort by current direction
    if(sortColumn.classList.contains('asc')) {
        data.sortAsc(sortColumn.key);
    } else {
        data.sortDesc(sortColumn.key);
    }
}

I won't mark this as closed as I feel it'd be worth adding this functionality automatically

@vincjo vincjo closed this as completed Jun 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants