Skip to content

Keep sort state after updating table's data #45

@superjojo140

Description

@superjojo140

After updating the table's data with table.setData() the sort state is not consistent. I tried to fix this by calling the table.sortData(columnName,sortingDirection) function manually with the current sort-state-values found in table._sorting property after updating the table's data.

This works, but the sortingDirection is swapped after calling the table.sortData() function. Why does that happen?

table.sortData("userId","asc"); //Sort by column userId in asc order
console.log(table._sorted) //Will print: {dir: 'desc', currentCol: 'userId'}

I also tried to found a workaround for this, by swapping the sorting direction values again... 😂 So this works for me now:

let table = $('#tableContainer').tableSortable(tableOptions);
table.setData(tableDataList,null);
//Keep sorting state consistent (the table plugin does not care about this...)
let sort = table._sorting;
sort.currentCol = sort.currentCol == '' ? "userId" : sort.currentCol;
sort.dir = sort.dir == '' ? "desc" : (sort.dir == "asc" ? "desc" : "asc"); //<-- Yes, this looks ugly, but the sorting logic of this table-plugin is really crazy :D
table.sortData(sort.currentCol,sort.dir);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions