1
0
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:
Allan Jardine 2010-09-14 19:43:04 +01:00
parent fb20b17856
commit 23fe13c68b
3 changed files with 75 additions and 14 deletions

View File

@ -2015,6 +2015,7 @@
*/
_fnAjustColumnSizing( oSettings );
_fnDraw( oSettings );
_fnSaveState( oSettings );
};
/*
@ -2049,6 +2050,9 @@
var nBody = oSettings.nTBody;
var i, iLen;
/* Flag to note that the table is currently being destoryed - no action should be taken */
oSettings.bDestroying = true;
/* Restore hidden columns */
for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
{
@ -5724,7 +5728,7 @@
*/
function _fnSaveState ( oSettings )
{
if ( !oSettings.oFeatures.bStateSave )
if ( !oSettings.oFeatures.bStateSave || typeof oSettings.bDestroying != 'undefined' )
{
return;
}
@ -6480,30 +6484,35 @@
/*
* 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 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;
var nTh = anThs ? anThs[i] : null;
/* Check if we have column visibilty state to restore, and also that the length of the
* state saved columns matches the currently know number of columns
*/
oInit.aoColumns = [];
for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
{
oInit.aoColumns.push( null );
}
}
/* 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 ( 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 */

View File

@ -36,5 +36,18 @@ $(document).ready( function () {
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();
} );

View 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();
} );