Skip to content

Commit

Permalink
e5bbe90f5ddb2e0016f6d8c158390b046c7d923a dev: Need columns visibility…
Browse files Browse the repository at this point in the history
… to be restoreable when using statesave not at initialisation

Jira Issue DD-2187

Sync to source repo @e5bbe90f5ddb2e0016f6d8c158390b046c7d923a
  • Loading branch information
AllanJard committed Sep 15, 2021
1 parent d237bed commit 90940b2
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 164 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
],
"src-repo": "http://github.com/DataTables/DataTablesSrc",
"last-tag": "1.11.2",
"last-sync": "a9f7bdf49784b713583995c0fd1863a279ed6533"
"last-sync": "e5bbe90f5ddb2e0016f6d8c158390b046c7d923a"
}
18 changes: 17 additions & 1 deletion js/jquery.dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -6423,6 +6423,10 @@
var i, ien;
var columns = settings.aoColumns;

// When StateRestore was introduced the state could now be implemented at any time
// Not just initialisation. To do this an api instance is required in some places
var api = settings._bInitComplete ? new DataTable.Api(settings) : null;

if ( ! s || ! s.time ) {
callback();
return;
Expand Down Expand Up @@ -6486,14 +6490,26 @@

// Visibility
if ( col.visible !== undefined ) {
columns[i].bVisible = col.visible;
// If the api is defined, the table has been initialised so we need to use it rather than internal settings
if (api) {
// Don't redraw the columns on every iteration of this loop, we will do this at the end instead
api.column(i).visible(col.visible, false);
}
else {
columns[i].bVisible = col.visible;
}
}

// Search
if ( col.search !== undefined ) {
$.extend( settings.aoPreSearchCols[i], _fnSearchToHung( col.search ) );
}
}

// If the api is defined then we need to adjust the columns once the visibility has been changed
if (api) {
api.columns.adjust();
}
}

_fnCallbackFire( settings, 'aoStateLoaded', 'stateLoaded', [settings, s] );
Expand Down
Loading

0 comments on commit 90940b2

Please sign in to comment.