(bug 41886) jquery.tablesorter should not explode rowspans until sorted
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 9 Nov 2012 19:48:46 +0000 (11:48 -0800)
committerMatmaRex <matma.rex@gmail.com>
Wed, 14 Nov 2012 19:16:08 +0000 (20:16 +0100)
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
resources/jquery/jquery.tablesorter.js
tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js

index 31ce2e3..23e25b7 100644 (file)
@@ -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
index 75dd2f1..9e2788e 100644 (file)
                                        // Declare and cache.
                                        var $document, $headers, cache, config, sortOrder,
                                                $table = $( table ),
-                                               shiftDown = 0;
+                                               shiftDown = 0,
+                                               firstTime = true;
 
                                        // Quit if no tbody
                                        if ( !table.tBodies ) {
                                        // 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 <tfoot> at the end of the <table>
-                                       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( $( '<tfoot>' ).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 <tfoot> at the end of the <table>
+                                               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( $( '<tfoot>' ).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?
                                                        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
                                         */
                                        $table.data( 'tablesorter' ).sort = function( sortList ) {
 
+                                               if ( firstTime ) {
+                                                       setupForFirstSort();
+                                               }
+
                                                if ( sortList === undefined ) {
                                                        sortList = config.sortList;
                                                } else if ( sortList.length > 0 ) {
 
                                        // sort initially
                                        if ( config.sortList.length > 0 ) {
-                                               explodeRowspans( $table );
+                                               setupForFirstSort();
                                                config.sortList = convertSortList( config.sortList );
                                                $table.data( 'tablesorter' ).sort();
                                        }
index b04a213..ef71dd0 100644 (file)
                }
        );
 
+       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' ] ];
 
                        '</table>'
                );
                $table.tablesorter();
+               $table.find( '.headerSort:eq(0)' ).click();
 
                assert.equal(
                        $table.data( 'tablesorter' ).config.parsers[0].id,