From b30c3a3de94748a8f2d1b0fb4806f6fece600b44 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 9 Nov 2012 11:48:46 -0800 Subject: [PATCH] (bug 41886) jquery.tablesorter should not explode rowspans until sorted jquery.tablesorter should not explode rowspans until the table is actually sorted. Also adds a testcase to verify this behavior, and updates another test case that was depending on the broken behavior. Change-Id: Ibe4cc7e92de6cc8e370c5912c9eda062b466c538 --- RELEASE-NOTES-1.21 | 2 + resources/jquery/jquery.tablesorter.js | 48 +++++++++++-------- .../jquery/jquery.tablesorter.test.js | 20 ++++++++ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 31ce2e391b..23e25b7321 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -67,6 +67,8 @@ production. * (bug 41990) Fix regression: API edit with redirect=true and lacking starttimestamp and basetimestamp should not cause an edit conflict. * (bug 41706) EditPage: Preloaded page should be converted if possible and needed. +* (bug 41886) Rowspans are no longer exploded by tablesorter until the table is + actually sorted. === API changes in 1.21 === * prop=revisions can now report the contentmodel and contentformat, see docs/contenthandler.txt diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 75dd2f1720..9e2788eeca 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -545,7 +545,8 @@ // Declare and cache. var $document, $headers, cache, config, sortOrder, $table = $( table ), - shiftDown = 0; + shiftDown = 0, + firstTime = true; // Quit if no tbody if ( !table.tBodies ) { @@ -589,26 +590,27 @@ // performance improvements in some browsers. cacheRegexs(); - // Legacy fix of .sortbottoms - // Wrap them inside inside a tfoot (because that's what they actually want to be) & - // and put the at the end of the - var $sortbottoms = $table.find( '> tbody > tr.sortbottom' ); - if ( $sortbottoms.length ) { - var $tfoot = $table.children( 'tfoot' ); - if ( $tfoot.length ) { - $tfoot.eq(0).prepend( $sortbottoms ); - } else { - $table.append( $( '' ).append( $sortbottoms ) ); + function setupForFirstSort() { + firstTime = false; + + // Legacy fix of .sortbottoms + // Wrap them inside inside a tfoot (because that's what they actually want to be) & + // and put the at the end of the
+ var $sortbottoms = $table.find( '> tbody > tr.sortbottom' ); + if ( $sortbottoms.length ) { + var $tfoot = $table.children( 'tfoot' ); + if ( $tfoot.length ) { + $tfoot.eq(0).prepend( $sortbottoms ); + } else { + $table.append( $( '' ).append( $sortbottoms ) ); + } } - } - - explodeRowspans( $table ); - // try to auto detect column type, and store in tables config - table.config.parsers = buildParserCache( table, $headers ); + explodeRowspans( $table ); - // initially build the cache for the tbody cells (to be able to sort initially) - cache = buildCache( table ); + // try to auto detect column type, and store in tables config + table.config.parsers = buildParserCache( table, $headers ); + }; // Apply event handling to headers // this is too big, perhaps break it out? @@ -619,6 +621,10 @@ return true; } + if ( firstTime ) { + setupForFirstSort(); + } + // Build the cache for the tbody cells // to share between calculations for this sort action. // Re-calculated each time a sort action is performed due to possiblity @@ -697,6 +703,10 @@ */ $table.data( 'tablesorter' ).sort = function( sortList ) { + if ( firstTime ) { + setupForFirstSort(); + } + if ( sortList === undefined ) { sortList = config.sortList; } else if ( sortList.length > 0 ) { @@ -715,7 +725,7 @@ // sort initially if ( config.sortList.length > 0 ) { - explodeRowspans( $table ); + setupForFirstSort(); config.sortList = convertSortList( config.sortList ); $table.data( 'tablesorter' ).sort(); } diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index b04a21316f..ef71dd0eb4 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -393,6 +393,25 @@ } ); + QUnit.test( 'Rowspan not exploded on init', 1, function ( assert ) { + var $table = tableCreate( header, planets ); + + // Modify the table to have a multiple-row-spanning cell: + // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row. + $table.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove(); + // - Set rowspan for 2nd cell of 3rd row to 3. + // This covers the removed cell in the 4th and 5th row. + $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan', '3' ); + + $table.tablesorter(); + + assert.equal( + $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan' ), + 3, + 'Rowspan not exploded' + ); + }); + var planetsRowspan = [ [ 'Earth', '6051.8' ], jupiter, [ 'Mars', '6051.8' ], mercury, saturn, venus ]; var planetsRowspanII = [ jupiter, mercury, saturn, venus, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ]; @@ -537,6 +556,7 @@ '
' ); $table.tablesorter(); + $table.find( '.headerSort:eq(0)' ).click(); assert.equal( $table.data( 'tablesorter' ).config.parsers[0].id, -- 2.20.1