Merge "jquery.tablesorter: Only look at th's for headers"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 15 Aug 2014 13:32:49 +0000 (13:32 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 15 Aug 2014 13:32:49 +0000 (13:32 +0000)
resources/src/jquery/jquery.tablesorter.js
tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js

index b46ab37..ea2c5f9 100644 (file)
                        } );
                        // We want to find the row that has the most columns (ignoring colspan)
                        $.each( exploded, function ( index, cellArray ) {
-                               headerCount = $.unique( $( cellArray ) ).length;
+                               headerCount = $( uniqueElements( cellArray ) ).filter( 'th' ).length;
                                if ( headerCount >= maxSeen ) {
                                        maxSeen = headerCount;
                                        longestTR = index;
                                }
                        } );
                        // We cannot use $.unique() here because it sorts into dom order, which is undesirable
-                       $tableHeaders = $( uniqueElements( exploded[longestTR] ) );
+                       $tableHeaders = $( uniqueElements( exploded[longestTR] ) ).filter( 'th' );
                }
 
                // as each header can span over multiple columns (using colspan=N),
index 2fd3ce9..92dad9f 100644 (file)
                );
                $table.tablesorter();
                assert.equal( $table.find( '#A2' ).prop( 'headerIndex' ),
-                       0,
+                       undefined,
                        'A2 should not be a sort header'
                );
                assert.equal( $table.find( '#C1' ).prop( 'headerIndex' ),
-                       1,
-                       'C1 should be a sort header, but will sort the wrong column'
+                       2,
+                       'C1 should be a sort header'
+               );
+       } );
+
+       // bug 53527
+       QUnit.test( 'td cells in thead should not be taken into account for longest row calculation', 2, function ( assert ) {
+               var $table = $(
+                       '<table class="sortable">' +
+                               '<thead>' +
+                               '<tr><th id="A1">A1</th><th>B1</th><td id="C1">C1</td></tr>' +
+                               '<tr><th id="A2">A2</th><th>B2</th><th id="C2">C2</th></tr>' +
+                               '</thead>' +
+                               '</table>'
+               );
+               $table.tablesorter();
+               assert.equal( $table.find( '#C2' ).prop( 'headerIndex' ),
+                       2,
+                       'C2 should be a sort header'
+               );
+               assert.equal( $table.find( '#C1' ).prop( 'headerIndex' ),
+                       undefined,
+                       'C1 should not be a sort header'
                );
        } );