Restoring initial ordering
Restoring initial ordering
I have an initial ordering that works they way that most users want. However, users may decide to try their own ordering by using the column controls. I have a button (Default Sort) that is intended to restore the table to the initial state. However, it only seems to partially work. The click call back happens and some ordering related to the ordering desired happens but the resulting ordering seems to retain some of the user's column selections. (The default ordering is based on some invisible columns).
const defaultOrder = [[10, 'asc'], [11, 'asc'], [9, 'asc'], [3, 'asc']];
const targetTable = $targetTable.DataTable({
paging: false,
dom: 'ritri',
order: defaultOrder,
columns: [
...
$('#btn-default-sort').on('click', function () {
targetTable.order(defaultOrder).draw();
});
The DataTables Debugger shows no failures or warnings. (Data uploaded to https://debug.datatables.net/otuzob ).
How can I get get the original ordering?
This question has an accepted answers - jump to answer
Answers
Of course, once you post something you realize the answer. I needed to clear the sorting columns back to the initial state, too.
The real problem is that the ordering "const" object is getting changed when the column headers are activated. The solution is is to make a deep copy of the defaultOrder object so that modification to the order does not change the original object.
So, the revised version is now:
Glad that's all sorted
C