// 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();
}
}
);
+ 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,