Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep sort state after updating table's data #45

Open
superjojo140 opened this issue Feb 28, 2024 · 0 comments
Open

Keep sort state after updating table's data #45

superjojo140 opened this issue Feb 28, 2024 · 0 comments

Comments

@superjojo140
Copy link

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant