svelte-simple-datatables
svelte-simple-datatables copied to clipboard
Re-apply current sorting upon data change
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.
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