mirror of
https://github.com/DataTables/DataTables.git
synced 2025-02-20 18:54:15 +01:00
New: API method columns().visible() - get / set column visiblity
- This effectively replaces the old fnSetColumnVis method (a shim will be put in place along with the shim for the rest of the old API). It has added get abilities, and the option, like the rest of the new API to work on multiple tables / columns with a single call depending on the context and selector.
This commit is contained in:
parent
8e1bf972d4
commit
bbb423ee75
@ -66,5 +66,76 @@ _api.register( 'columns().data()', function () {
|
||||
} );
|
||||
|
||||
|
||||
|
||||
|
||||
_api.register( 'columns().visible()', function ( vis ) {
|
||||
return this.iterator( 'column', function ( settings, column ) {
|
||||
var
|
||||
cols = settings.aoColumns,
|
||||
col = cols[ column ],
|
||||
data = settings.aoData,
|
||||
row, cells, i, ien, tr;
|
||||
|
||||
// Get
|
||||
if ( vis === undefined ) {
|
||||
return col.bVisible;
|
||||
}
|
||||
|
||||
// Set
|
||||
// No change
|
||||
if ( col.bVisible === vis ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( vis ) {
|
||||
// Insert column
|
||||
// Need to decide if we should use appendChild or insertBefore
|
||||
var insertBefore = $.inArray( true, _pluck(cols, 'bVisible'), column+1 );
|
||||
|
||||
for ( i=0, ien=data.length ; i<ien ; i++ ) {
|
||||
tr = data[i].nTr;
|
||||
cells = data[i].anCells;
|
||||
|
||||
if ( tr ) {
|
||||
// insertBefore can act like appendChild if 2nd arg is null
|
||||
tr.insertBefore( cells[ column ], cells[ insertBefore ] || null );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Remove column
|
||||
$( _pluck( settings.aoData, 'anCells', column ) ).remove();
|
||||
|
||||
col.bVisible = false;
|
||||
_fnDrawHead( settings, settings.aoHeader );
|
||||
_fnDrawHead( settings, settings.aoFooter );
|
||||
|
||||
_fnSaveState( settings );
|
||||
}
|
||||
|
||||
// Common actions
|
||||
col.bVisible = vis;
|
||||
_fnDrawHead( settings, settings.aoHeader );
|
||||
_fnDrawHead( settings, settings.aoFooter );
|
||||
|
||||
_fnSaveState( settings );
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
// _api.register( 'columns().show()', function () {
|
||||
// var selector = this.selector;
|
||||
// return this.columns( selector.cols, selector.opts ).visible( true );
|
||||
// } );
|
||||
|
||||
|
||||
// _api.register( 'columns().hide()', function () {
|
||||
// var selector = this.selector;
|
||||
// return this.columns( selector.cols, selector.opts ).visible( false );
|
||||
// } );
|
||||
|
||||
|
||||
|
||||
|
||||
}());
|
||||
|
||||
|
@ -225,6 +225,11 @@ function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
|
||||
var iColumns = oSettings.aoColumns.length;
|
||||
var iRowspan, iColspan;
|
||||
|
||||
if ( ! aoSource )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( bIncludeHidden === undefined )
|
||||
{
|
||||
bIncludeHidden = false;
|
||||
|
@ -22,10 +22,7 @@ function _fnInitialise ( oSettings )
|
||||
/* Build and draw the header / footer for the table */
|
||||
_fnBuildHead( oSettings );
|
||||
_fnDrawHead( oSettings, oSettings.aoHeader );
|
||||
if ( oSettings.nTFoot )
|
||||
{
|
||||
_fnDrawHead( oSettings, oSettings.aoFooter );
|
||||
}
|
||||
_fnDrawHead( oSettings, oSettings.aoFooter );
|
||||
|
||||
/* Okay to show that something is going on now */
|
||||
_fnProcessingDisplay( oSettings, true );
|
||||
|
Loading…
x
Reference in New Issue
Block a user