svelte-simple-datatables icon indicating copy to clipboard operation
svelte-simple-datatables copied to clipboard

Re-apply current sorting upon data change

Open MattPurland opened this issue 3 years ago • 1 comments

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 avatar May 05 '21 10:05 MattPurland

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

MattPurland avatar May 05 '21 13:05 MattPurland