Skip to content
Browse files

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.
  • Loading branch information...
1 parent 8e1068e commit cab0c534f1b49bed096ec6ac82ab91aa739a7ed0 @DataTables committed Oct 19, 2012
View
27 media/js/jquery.dataTables.js
@@ -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();
}
/*
View
27 media/src/core/core.constructor.js
@@ -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();
}
/*
View
61 media/unit_testing/tests_onhold/1_dom/gh125 - stripe stripping.js
@@ -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();
+} );

0 comments on commit cab0c53

Please sign in to comment.
Something went wrong with that request. Please try again.