Merge pull request #27 from globalinnovation/master

Update fnAddTr.js - Fix - Showing invisible columns - Adding the TD to the hidden element list (_anHidden)
pull/28/head
Allan Jardine 11 years ago
commit 2d7d1f1907

@ -14,27 +14,40 @@ $.fn.dataTableExt.oApi.fnAddTr = function ( oSettings, nTr, bRedraw ) {
{ {
bRedraw = true; bRedraw = true;
} }
var nTds = nTr.getElementsByTagName('td'); var nTds = nTr.getElementsByTagName('td');
if ( nTds.length != oSettings.aoColumns.length ) if ( nTds.length != oSettings.aoColumns.length )
{ {
alert( 'Warning: not adding new TR - columns and TD elements must match' ); alert( 'Warning: not adding new TR - columns and TD elements must match' );
return; return;
} }
var aData = []; var aData = [];
var aInvisible = [];
for ( var i=0 ; i<nTds.length ; i++ ) for ( var i=0 ; i<nTds.length ; i++ )
{ {
aData.push( nTds[i].innerHTML ); aData.push( nTds[i].innerHTML );
if (!oSettings.aoColumns[i].bVisible)
{
aInvisible.push( i );
}
} }
/* Add the data and then replace DataTable's generated TR with ours */ /* Add the data and then replace DataTable's generated TR with ours */
var iIndex = this.oApi._fnAddData( oSettings, aData ); var iIndex = this.oApi._fnAddData( oSettings, aData );
nTr._DT_RowIndex = iIndex; nTr._DT_RowIndex = iIndex;
oSettings.aoData[ iIndex ].nTr = nTr; oSettings.aoData[ iIndex ].nTr = nTr;
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice(); oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
// Hidding invisible columns
for ( var i = (aInvisible.length - 1) ; i >= 0 ; i-- )
{
oSettings.aoData[iIndex]._anHidden[ i ] = nTds[aInvisible[i]];
nTr.removeChild( nTds[aInvisible[i]] );
}
// Redraw
if ( bRedraw ) if ( bRedraw )
{ {
this.oApi._fnReDraw( oSettings ); this.oApi._fnReDraw( oSettings );

Loading…
Cancel
Save