From 11da46af785239b813e5b1e6e00038feef298e1a Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Sun, 2 Oct 2011 11:58:46 +0000 Subject: [PATCH] Add tfoot emulation to tablesorter. Fixes part of the complaints in bug 31060 --- resources/jquery/jquery.tablesorter.js | 43 ++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 0030b4cb30..8150254fd1 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -224,19 +224,36 @@ * This only treats a row as a header row if it contains only s (no s) * and if it is preceded entirely by header rows. The algorithm stops when * it encounters the first non-header row. + * + * After this, it will look at all rows at the bottom for footer rows + * And place these in a tfoot using similar rules. * @param $table jQuery object for a */ - function emulateTHead( $table ) { - var $thead = $( '' ); - $table.find( 'tr' ).each( function() { - if ( $(this).children( 'td' ).length > 0 ) { - // This row contains a ' ); + $rows.each( function() { + if ( $(this).children( 'td' ).length > 0 ) { + // This row contains a ' ); + var len = $rows.length; + for ( var i = len-1; i >= 0; i-- ) { + if( $( $rows[i] ).children( 'td' ).length > 0 ){ + break; + } + $tfoot.prepend( $( $rows[i] )); + } + $table.append( $tfoot ); + } } function buildHeaders( table, msg ) { @@ -532,8 +549,8 @@ } if ( !table.tHead ) { // No thead found. Look for rows with tag - emulateTHead( $table ); + // move them into a tag or a tag + emulateTHeadAndFoot( $table ); // Still no thead? Then quit if ( !table.tHead ) { -- 2.20.1
, so it's not a header row - // Stop here - return false; - } - $thead.append( this ); - } ); - $table.prepend( $thead ); + function emulateTHeadAndFoot( $table ) { + var $rows = $table.find( 'tr' ); + if( !$table.get(0).tHead ) { + var $thead = $( '
, so it's not a header row + // Stop here + return false; + } + $thead.append( this ); + } ); + $table.prepend( $thead ); + } + if( !$table.get(0).tFoot ) { + var $tfoot = $( '
s and - // move them into a