Skip to content

Commit 90940b2

Browse files
committedSep 15, 2021
e5bbe90f5ddb2e0016f6d8c158390b046c7d923a dev: Need columns visibility to be restoreable when using statesave not at initialisation
Jira Issue DD-2187 Sync to source repo @e5bbe90f5ddb2e0016f6d8c158390b046c7d923a
1 parent d237bed commit 90940b2

File tree

3 files changed

+180
-164
lines changed

3 files changed

+180
-164
lines changed
 

‎datatables.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
],
1010
"src-repo": "http://github.com/DataTables/DataTablesSrc",
1111
"last-tag": "1.11.2",
12-
"last-sync": "a9f7bdf49784b713583995c0fd1863a279ed6533"
12+
"last-sync": "e5bbe90f5ddb2e0016f6d8c158390b046c7d923a"
1313
}

‎js/jquery.dataTables.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -6423,6 +6423,10 @@
64236423
var i, ien;
64246424
var columns = settings.aoColumns;
64256425

6426+
// When StateRestore was introduced the state could now be implemented at any time
6427+
// Not just initialisation. To do this an api instance is required in some places
6428+
var api = settings._bInitComplete ? new DataTable.Api(settings) : null;
6429+
64266430
if ( ! s || ! s.time ) {
64276431
callback();
64286432
return;
@@ -6486,14 +6490,26 @@
64866490

64876491
// Visibility
64886492
if ( col.visible !== undefined ) {
6489-
columns[i].bVisible = col.visible;
6493+
// If the api is defined, the table has been initialised so we need to use it rather than internal settings
6494+
if (api) {
6495+
// Don't redraw the columns on every iteration of this loop, we will do this at the end instead
6496+
api.column(i).visible(col.visible, false);
6497+
}
6498+
else {
6499+
columns[i].bVisible = col.visible;
6500+
}
64906501
}
64916502

64926503
// Search
64936504
if ( col.search !== undefined ) {
64946505
$.extend( settings.aoPreSearchCols[i], _fnSearchToHung( col.search ) );
64956506
}
64966507
}
6508+
6509+
// If the api is defined then we need to adjust the columns once the visibility has been changed
6510+
if (api) {
6511+
api.columns.adjust();
6512+
}
64976513
}
64986514

64996515
_fnCallbackFire( settings, 'aoStateLoaded', 'stateLoaded', [settings, s] );

‎js/jquery.dataTables.min.js

+162-162
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.