From: Derk-Jan Hartman Date: Mon, 1 Jul 2013 21:19:50 +0000 (+0200) Subject: Tablesorter: colSpan property was incorrectly accessed X-Git-Tag: 1.31.0-rc.0~19251^2 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=6f38c7aa0611ef8631308606a4683d2aa1518fbb;p=lhc%2Fweb%2Fwiklou.git Tablesorter: colSpan property was incorrectly accessed Due to mixing up of colspan attribute and colSpan property, the condition always resolved to 1. This effectively made it a headerIndex. Renamed it as such and moved the building of the header/column mappings into the buildHeaders function, where it is more suited. Bug: 47654 Change-Id: I264afb565afbe555733bad499bad6f9c87894982 --- diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 97357d9be9..d20d280dbd 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -287,8 +287,10 @@ function buildHeaders( table, msg ) { var maxSeen = 0, + colspanOffset = 0, longest, - realCellIndex = 0, + columns, + i, $tableHeaders = $( [] ), $tableRows = $( 'thead:eq(0) > tr', table ); if ( $tableRows.length <= 1 ) { @@ -296,7 +298,6 @@ } else { // We need to find the cells of the row containing the most columns var rowspan, - i, headersIndex = []; $tableRows.each( function ( rowIndex ) { $.each( this.cells, function( index2, cell ) { @@ -317,13 +318,23 @@ } ); $tableHeaders = headersIndex[longest]; } - $tableHeaders.each( function ( index ) { - this.column = realCellIndex; - var colspan = this.colspan; - colspan = colspan ? parseInt( colspan, 10 ) : 1; - realCellIndex += colspan; + // as each header can span over multiple columns (using colspan=N), + // we have to bidirectionally map headers to their columns and columns to their headers + table.headerToColumns = []; + table.columnToHeader = []; + $tableHeaders.each( function ( headerIndex ) { + columns = []; + for ( i = 0; i < this.colSpan; i++ ) { + table.columnToHeader[ colspanOffset + i ] = headerIndex; + columns.push( colspanOffset + i ); + } + + table.headerToColumns[ headerIndex ] = columns; + colspanOffset += this.colSpan; + + this.headerIndex = headerIndex; this.order = 0; this.count = 0; @@ -336,7 +347,7 @@ } // add cell to headerList - table.config.headerList[index] = this; + table.config.headerList[headerIndex] = this; } ); return $tableHeaders; @@ -663,7 +674,6 @@ return $tables.each( function ( i, table ) { // Declare and cache. var $headers, cache, config, - headerToColumns, columnToHeader, colspanOffset, $table = $( table ), firstTime = true; @@ -731,22 +741,6 @@ table.config.parsers = buildParserCache( table, $headers ); } - // as each header can span over multiple columns (using colspan=N), - // we have to bidirectionally map headers to their columns and columns to their headers - headerToColumns = []; - columnToHeader = []; - colspanOffset = 0; - $headers.each( function ( headerIndex ) { - var columns = []; - for ( var i = 0; i < this.colSpan; i++ ) { - columnToHeader[ colspanOffset + i ] = headerIndex; - columns.push( colspanOffset + i ); - } - - headerToColumns[ headerIndex ] = columns; - colspanOffset += this.colSpan; - } ); - // Apply event handling to headers // this is too big, perhaps break it out? $headers.filter( ':not(.unsortable)' ).click( function ( e ) { @@ -776,7 +770,7 @@ var cell = this; // Get current column index - var columns = headerToColumns[this.column]; + var columns = table.headerToColumns[ this.headerIndex ]; var newSortList = $.map( columns, function (c) { // jQuery "helpfully" flattens the arrays... return [[c, cell.order]]; @@ -811,10 +805,10 @@ } // Reset order/counts of cells not affected by sorting - setHeadersOrder( $headers, config.sortList, headerToColumns ); + setHeadersOrder( $headers, config.sortList, table.headerToColumns ); // Set CSS for headers - setHeadersCss( $table[0], $headers, config.sortList, sortCSS, sortMsg, columnToHeader ); + setHeadersCss( $table[0], $headers, config.sortList, sortCSS, sortMsg, table.columnToHeader ); appendToTable( $table[0], multisort( $table[0], config.sortList, cache ) ); @@ -855,13 +849,13 @@ // Set each column's sort count to be able to determine the correct sort // order when clicking on a header cell the next time - setHeadersOrder( $headers, sortList, headerToColumns ); + setHeadersOrder( $headers, sortList, table.headerToColumns ); // re-build the cache for the tbody cells cache = buildCache( table ); // set css for headers - setHeadersCss( table, $headers, sortList, sortCSS, sortMsg, columnToHeader ); + setHeadersCss( table, $headers, sortList, sortCSS, sortMsg, table.columnToHeader ); // sort the table and append it to the dom appendToTable( table, multisort( table, sortList, cache ) );