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);
After updating the table's data with
table.setData()the sort state is not consistent. I tried to fix this by calling thetable.sortData(columnName,sortingDirection)function manually with the current sort-state-values found intable._sortingproperty after updating the table's data.This works, but the sortingDirection is swapped after calling the
table.sortData()function. Why does that happen?I also tried to found a workaround for this, by swapping the sorting direction values again... 😂 So this works for me now: