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:
parent
8e1068e603
commit
cab0c534f1
27
media/js/jquery.dataTables.js
vendored
27
media/js/jquery.dataTables.js
vendored
@ -6617,27 +6617,12 @@
|
||||
}
|
||||
|
||||
/* Remove row stripe classes if they are already on the table row */
|
||||
iLen=oSettings.asStripeClasses.length;
|
||||
oSettings.asDestroyStripes = [];
|
||||
if (iLen)
|
||||
{
|
||||
var bStripeRemove = false;
|
||||
var anRows = $(this).children('tbody').children('tr:lt(' + iLen + ')');
|
||||
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(' ') );
|
||||
}
|
||||
var stripeClasses = oSettings.asStripeClasses;
|
||||
if ( $.inArray( true, $.map( stripeClasses, function(el, i) {
|
||||
return $('tbody tr:eq(0)', this).hasClass(el);
|
||||
} ) ) !== -1 ) {
|
||||
$('tbody tr', this).removeClass( stripeClasses.join(' ') );
|
||||
oSettings.asDestroyStripes = stripeClasses.slice();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -244,27 +244,12 @@ if ( oInit.asStripeClasses === null )
|
||||
}
|
||||
|
||||
/* Remove row stripe classes if they are already on the table row */
|
||||
iLen=oSettings.asStripeClasses.length;
|
||||
oSettings.asDestroyStripes = [];
|
||||
if (iLen)
|
||||
{
|
||||
var bStripeRemove = false;
|
||||
var anRows = $(this).children('tbody').children('tr:lt(' + iLen + ')');
|
||||
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(' ') );
|
||||
}
|
||||
var stripeClasses = oSettings.asStripeClasses;
|
||||
if ( $.inArray( true, $.map( stripeClasses, function(el, i) {
|
||||
return $('tbody tr:eq(0)', this).hasClass(el);
|
||||
} ) ) !== -1 ) {
|
||||
$('tbody tr', this).removeClass( stripeClasses.join(' ') );
|
||||
oSettings.asDestroyStripes = stripeClasses.slice();
|
||||
}
|
||||
|
||||
/*
|
||||
|
61
media/unit_testing/tests_onhold/1_dom/gh125 - stripe stripping.js
Executable file
61
media/unit_testing/tests_onhold/1_dom/gh125 - stripe stripping.js
Executable 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();
|
||||
} );
|
Loading…
x
Reference in New Issue
Block a user