1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-03-15 16:29:16 +01:00

Fix - core: Stripe removal was broken - it was stripping the classes from only the first row rows, rather than all of them, which was wrong. This was unfortunatly introduced in 1.9.4 and there weren't any unit tests to catch it. There are now, and I've rewritten the code that wil remove existing stripe classes. Its now much smaller and should be a little faster. Now it only checks the first row to see if it has any exisiting stripe classes, which is good enough. The smallest this could could be would be a simple removeClass, but that may result in significant overhead which really isn't needed in cases where there are no exisiting stripe classes.

This commit is contained in:
Allan Jardine 2012-10-19 15:31:35 +01:00
parent 8e1068e603
commit cab0c534f1
3 changed files with 73 additions and 42 deletions

View File

@ -6617,27 +6617,12 @@
} }
/* Remove row stripe classes if they are already on the table row */ /* Remove row stripe classes if they are already on the table row */
iLen=oSettings.asStripeClasses.length; var stripeClasses = oSettings.asStripeClasses;
oSettings.asDestroyStripes = []; if ( $.inArray( true, $.map( stripeClasses, function(el, i) {
if (iLen) return $('tbody tr:eq(0)', this).hasClass(el);
{ } ) ) !== -1 ) {
var bStripeRemove = false; $('tbody tr', this).removeClass( stripeClasses.join(' ') );
var anRows = $(this).children('tbody').children('tr:lt(' + iLen + ')'); oSettings.asDestroyStripes = stripeClasses.slice();
for ( i=0 ; i<iLen ; i++ )
{
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] );
}
}
if ( bStripeRemove )
{
anRows.removeClass( oSettings.asStripeClasses.join(' ') );
}
} }
/* /*

View File

@ -244,27 +244,12 @@ if ( oInit.asStripeClasses === null )
} }
/* Remove row stripe classes if they are already on the table row */ /* Remove row stripe classes if they are already on the table row */
iLen=oSettings.asStripeClasses.length; var stripeClasses = oSettings.asStripeClasses;
oSettings.asDestroyStripes = []; if ( $.inArray( true, $.map( stripeClasses, function(el, i) {
if (iLen) return $('tbody tr:eq(0)', this).hasClass(el);
{ } ) ) !== -1 ) {
var bStripeRemove = false; $('tbody tr', this).removeClass( stripeClasses.join(' ') );
var anRows = $(this).children('tbody').children('tr:lt(' + iLen + ')'); oSettings.asDestroyStripes = stripeClasses.slice();
for ( i=0 ; i<iLen ; i++ )
{
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] );
}
}
if ( bStripeRemove )
{
anRows.removeClass( oSettings.asStripeClasses.join(' ') );
}
} }
/* /*

View File

@ -0,0 +1,61 @@
// DATA_TEMPLATE: dom_data
oTest.fnStart( "Odd and even are stripped from all rows" );
$(document).ready( function () {
$('table tbody tr').addClass( 'odd even' );
$('table.display').dataTable();
oTest.fnTest(
"Odd is applied to exactly 5 rows",
null,
function () {
return $('#example tbody tr.odd').length === 5;
}
);
oTest.fnTest(
"Even is applied to exactly 5 rows",
null,
function () {
return $('#example tbody tr.even').length === 5;
}
);
oTest.fnTest(
"First row is odd",
null,
function () {
return $('#example tbody tr:eq(0)').hasClass('odd') &&
! $('#example tbody tr:eq(0)').hasClass('even');
}
);
oTest.fnTest(
"Second row is even",
null,
function () {
return $('#example tbody tr:eq(1)').hasClass('even') &&
! $('#example tbody tr:eq(1)').hasClass('odd');
}
);
oTest.fnTest(
"Third row is odd",
null,
function () {
return $('#example tbody tr:eq(2)').hasClass('odd') &&
! $('#example tbody tr:eq(2)').hasClass('even');
}
);
oTest.fnTest(
"Fourth row is even",
null,
function () {
return $('#example tbody tr:eq(3)').hasClass('even') &&
! $('#example tbody tr:eq(3)').hasClass('odd');
}
);
oTest.fnComplete();
} );