mirror of
https://github.com/DataTables/DataTables.git
synced 2025-01-18 11:52:11 +01:00
Fixed: Column visibility was not being saved when calling fnSetColumnVis. It would require another draw to save the state before - 2635.
Fixed: Column visibility was not be restored from the state saving cookie. A small tidy up of the column creation code as well - 2635.
This commit is contained in:
parent
fb20b17856
commit
23fe13c68b
37
media/js/jquery.dataTables.js
vendored
37
media/js/jquery.dataTables.js
vendored
@ -2015,6 +2015,7 @@
|
|||||||
*/
|
*/
|
||||||
_fnAjustColumnSizing( oSettings );
|
_fnAjustColumnSizing( oSettings );
|
||||||
_fnDraw( oSettings );
|
_fnDraw( oSettings );
|
||||||
|
_fnSaveState( oSettings );
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2049,6 +2050,9 @@
|
|||||||
var nBody = oSettings.nTBody;
|
var nBody = oSettings.nTBody;
|
||||||
var i, iLen;
|
var i, iLen;
|
||||||
|
|
||||||
|
/* Flag to note that the table is currently being destoryed - no action should be taken */
|
||||||
|
oSettings.bDestroying = true;
|
||||||
|
|
||||||
/* Restore hidden columns */
|
/* Restore hidden columns */
|
||||||
for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
|
for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
|
||||||
{
|
{
|
||||||
@ -5724,7 +5728,7 @@
|
|||||||
*/
|
*/
|
||||||
function _fnSaveState ( oSettings )
|
function _fnSaveState ( oSettings )
|
||||||
{
|
{
|
||||||
if ( !oSettings.oFeatures.bStateSave )
|
if ( !oSettings.oFeatures.bStateSave || typeof oSettings.bDestroying != 'undefined' )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -6480,30 +6484,35 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Columns
|
* Columns
|
||||||
* See if we should load columns automatically or use defined ones - a bit messy this...
|
* See if we should load columns automatically or use defined ones
|
||||||
*/
|
*/
|
||||||
var nThead = this.getElementsByTagName('thead');
|
var nThead = this.getElementsByTagName('thead');
|
||||||
var anThs = nThead.length===0 ? [] : _fnGetUniqueThs( nThead[0] );
|
var anThs = nThead.length===0 ? [] : _fnGetUniqueThs( nThead[0] );
|
||||||
var bUseCols = typeof oInit.aoColumns != 'undefined';
|
|
||||||
|
|
||||||
for ( i=0, iLen=bUseCols ? oInit.aoColumns.length : anThs.length ; i<iLen ; i++ )
|
/* If not given a column array, generate one with nulls */
|
||||||
|
if ( typeof oInit.aoColumns == 'undefined' )
|
||||||
{
|
{
|
||||||
var oCol = bUseCols ? oInit.aoColumns[i] : null;
|
oInit.aoColumns = [];
|
||||||
var nTh = anThs ? anThs[i] : null;
|
for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
|
||||||
|
{
|
||||||
/* Check if we have column visibilty state to restore, and also that the length of the
|
oInit.aoColumns.push( null );
|
||||||
* state saved columns matches the currently know number of columns
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
/* Add the columns */
|
||||||
|
for ( i=0, iLen=oInit.aoColumns.length ; i<iLen ; i++ )
|
||||||
|
{
|
||||||
|
/* Check if we have column visibilty state to restore */
|
||||||
if ( typeof oInit.saved_aoColumns != 'undefined' && oInit.saved_aoColumns.length == iLen )
|
if ( typeof oInit.saved_aoColumns != 'undefined' && oInit.saved_aoColumns.length == iLen )
|
||||||
{
|
{
|
||||||
if ( oCol === null )
|
if ( oInit.aoColumns[i] === null )
|
||||||
{
|
{
|
||||||
oCol = {};
|
oInit.aoColumns[i] = {};
|
||||||
}
|
}
|
||||||
oCol.bVisible = oInit.saved_aoColumns[i].bVisible;
|
oInit.aoColumns[i].bVisible = oInit.saved_aoColumns[i].bVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
_fnAddColumn( oSettings, nTh );
|
_fnAddColumn( oSettings, anThs ? anThs[i] : null );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add options from column definations */
|
/* Add options from column definations */
|
||||||
|
@ -36,5 +36,18 @@ $(document).ready( function () {
|
|||||||
function () { return $('#example_filter input').val() == ''; }
|
function () { return $('#example_filter input').val() == ''; }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
oTest.fnTest(
|
||||||
|
"Clean up",
|
||||||
|
function () {
|
||||||
|
$('#example').dataTable( {
|
||||||
|
"bStateSave": true,
|
||||||
|
"bDestroy": true
|
||||||
|
} );
|
||||||
|
$('#example_filter input').val( '' );
|
||||||
|
$('#example_filter input').keyup();
|
||||||
|
},
|
||||||
|
function () { return $('#example_filter input').val() == ''; }
|
||||||
|
);
|
||||||
|
|
||||||
oTest.fnComplete();
|
oTest.fnComplete();
|
||||||
} );
|
} );
|
39
media/unit_testing/tests_onhold/1_dom/2635.js
Executable file
39
media/unit_testing/tests_onhold/1_dom/2635.js
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
// DATA_TEMPLATE: dom_data
|
||||||
|
oTest.fnStart( "2635 - Hiding column and state saving" );
|
||||||
|
|
||||||
|
$(document).ready( function () {
|
||||||
|
$('#example').dataTable( {
|
||||||
|
"bStateSave": true
|
||||||
|
} );
|
||||||
|
|
||||||
|
oTest.fnTest(
|
||||||
|
"Set the hidden column",
|
||||||
|
function () {
|
||||||
|
$('#example').dataTable().fnSetColumnVis( 2, false );
|
||||||
|
},
|
||||||
|
function () { return $('#example thead th').length == 4; }
|
||||||
|
);
|
||||||
|
|
||||||
|
oTest.fnTest(
|
||||||
|
"Destroy the table and remake it - checking one column was removed",
|
||||||
|
function () {
|
||||||
|
$('#example').dataTable( {
|
||||||
|
"bStateSave": true,
|
||||||
|
"bDestroy": true
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
function () { return $('#example thead th').length == 4; }
|
||||||
|
);
|
||||||
|
|
||||||
|
oTest.fnTest(
|
||||||
|
"Do it again without state saving and make sure we are back to 5 columns",
|
||||||
|
function () {
|
||||||
|
$('#example').dataTable( {
|
||||||
|
"bDestroy": true
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
function () { return $('#example thead th').length == 5; }
|
||||||
|
);
|
||||||
|
|
||||||
|
oTest.fnComplete();
|
||||||
|
} );
|
Loading…
x
Reference in New Issue
Block a user