mirror of
https://github.com/DataTables/DataTables.git
synced 2025-01-19 12:52:11 +01:00
Merge pull request #87 from timtucker/patch-4
Allow adding / removing an arbitrary number of stripes
This commit is contained in:
commit
1fdfb65457
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
/**
|
||||
* Perform a jQuery selector action on the table's TR elements (from the tbody) and
|
||||
* return the resulting jQuery object.
|
||||
@ -566,12 +564,19 @@ this.fnDestroy = function ( bRemove )
|
||||
oSettings.nTable.style.width = _fnStringToCss(oSettings.sDestroyWidth);
|
||||
}
|
||||
|
||||
/* If the were originally odd/even type classes - then we add them back here. Note
|
||||
* this is not fool proof (for example if not all rows as odd/even classes - but
|
||||
/* If the were originally stripe classes - then we add them back here. Note
|
||||
* this is not fool proof (for example if not all rows had stripe classes - but
|
||||
* it's a good effort without getting carried away
|
||||
*/
|
||||
$(nBody).children('tr:even').addClass( oSettings.asDestroyStripes[0] );
|
||||
$(nBody).children('tr:odd').addClass( oSettings.asDestroyStripes[1] );
|
||||
iLen = oSettings.asDestroyStripes.length;
|
||||
if (iLen)
|
||||
{
|
||||
var anRows = $(nBody).children('tr');
|
||||
for ( i=0 ; i<iLen ; i++ )
|
||||
{
|
||||
anRows.filter(':nth-child(' + iLen + 'n + ' + i + ')').addClass( oSettings.asDestroyStripes[i] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove the settings object from the settings array */
|
||||
for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
var i=0, iLen, j, jLen, k, kLen;
|
||||
var sId = this.getAttribute( 'id' );
|
||||
var bInitHandedOff = false;
|
||||
@ -240,42 +239,29 @@ if ( oInit.asStripeClasses === null )
|
||||
}
|
||||
|
||||
/* Remove row stripe classes if they are already on the table row */
|
||||
var bStripeRemove = false;
|
||||
var anRows = $(this).children('tbody').children('tr');
|
||||
for ( i=0, iLen=oSettings.asStripeClasses.length ; i<iLen ; i++ )
|
||||
iLen=oSettings.asStripeClasses.length;
|
||||
oSettings.asDestroyStripes = [];
|
||||
if (iLen)
|
||||
{
|
||||
if ( anRows.filter(":lt(2)").hasClass( oSettings.asStripeClasses[i]) )
|
||||
var bStripeRemove = false;
|
||||
var anRows = $(this).children('tbody').children('tr:lt(' + iLen + ')');
|
||||
for ( i=0 ; i<iLen ; i++ )
|
||||
{
|
||||
bStripeRemove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bStripeRemove )
|
||||
{
|
||||
/* Store the classes which we are about to remove so they can be re-added on destroy */
|
||||
oSettings.asDestroyStripes = [ '', '' ];
|
||||
if ( $(anRows[0]).hasClass(oSettings.oClasses.sStripeOdd) )
|
||||
{
|
||||
oSettings.asDestroyStripes[0] += oSettings.oClasses.sStripeOdd+" ";
|
||||
}
|
||||
if ( $(anRows[0]).hasClass(oSettings.oClasses.sStripeEven) )
|
||||
{
|
||||
oSettings.asDestroyStripes[0] += oSettings.oClasses.sStripeEven;
|
||||
}
|
||||
if ( $(anRows[1]).hasClass(oSettings.oClasses.sStripeOdd) )
|
||||
{
|
||||
oSettings.asDestroyStripes[1] += oSettings.oClasses.sStripeOdd+" ";
|
||||
}
|
||||
if ( $(anRows[1]).hasClass(oSettings.oClasses.sStripeEven) )
|
||||
{
|
||||
oSettings.asDestroyStripes[1] += oSettings.oClasses.sStripeEven;
|
||||
if ( anRows.hasClass( oSettings.asStripeClasses[i] ) )
|
||||
{
|
||||
bStripeRemove = true;
|
||||
|
||||
/* Store the classes which we are about to remove so they can be re-added on destroy */
|
||||
oSettings.asDestroyStripes.push( oSettings.asStripeClasses[i] );
|
||||
}
|
||||
}
|
||||
|
||||
anRows.removeClass( oSettings.asStripeClasses.join(' ') );
|
||||
if ( bStripeRemove )
|
||||
{
|
||||
anRows.removeClass( oSettings.asStripeClasses.join(' ') );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Columns
|
||||
* See if we should load columns automatically or use defined ones
|
||||
|
Loading…
x
Reference in New Issue
Block a user