From: Leo Koppelkamm Date: Mon, 2 May 2011 11:31:45 +0000 (+0000) Subject: Make jquery.tablesorter more resilient by checking multiple cells before assuming... X-Git-Tag: 1.31.0-rc.0~30463 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=73ea7301ece545f3d0179ed172d972c8482ee4fb;p=lhc%2Fweb%2Fwiklou.git Make jquery.tablesorter more resilient by checking multiple cells before assuming a type. Fixes Bug 28775 --- diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 5e017a1657..9c28008233 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -108,7 +108,7 @@ } if (p === false) { - p = detectParserForColumn( table, rows, -1, i ); + p = detectParserForColumn( table, rows, i ); } // if ( table.config.debug ) { // console.log( "column:" + i + " parser:" + p.id + "\n" ); @@ -119,40 +119,51 @@ return list; } - function detectParserForColumn( table, rows, rowIndex, cellIndex ) { + function detectParserForColumn( table, rows, cellIndex ) { var l = parsers.length, - node = false, - nodeValue = false, - keepLooking = true; - while ( nodeValue == '' && keepLooking ) { - rowIndex++; - if ( rows[rowIndex] ) { - node = getNodeFromRowAndCellIndex( rows, rowIndex, cellIndex ); - nodeValue = trimAndGetNodeText( node ); - // if ( table.config.debug ) { - // console.log( 'Checking if value was empty on row:' + rowIndex ); - // } + nodeValue, + // Start with 1 because 0 is the fallback parser + i = 1, + rowIndex = 0, + concurrent = 0, + needed = (rows.length > 4 ) ? 5 : rows.length; + while( i= needed ) { + // Confirmed the parser for multiple cells, let's return it + return parsers[i]; + } + } else { + // Check next parser, reset rows + i++; + rowIndex = 0; + } } else { - keepLooking = false; - } - } - for ( var i = 1; i < l; i++ ) { - if ( parsers[i].is( nodeValue, table, node ) ) { - return parsers[i]; + // Empty cell + rowIndex++; + if ( rowIndex > rows.length ) { + rowIndex = 0; + i++; + } } } + // 0 is always the generic parser ( text ) return parsers[0]; } - - function getNodeFromRowAndCellIndex( rows, rowIndex, cellIndex ) { - return rows[rowIndex].cells[cellIndex]; - } - - function trimAndGetNodeText( node ) { - return $.trim( getElementText( node ) ); + + function getTextFromRowAndCellIndex( rows, rowIndex, cellIndex ) { + if ( rows[rowIndex] && rows[rowIndex].cells[cellIndex] ) { + return $.trim( getElementText( rows[rowIndex].cells[cellIndex] ) ); + } else { + return ''; + } } - + function getParserById( name ) { var l = parsers.length; for ( var i = 0; i < l; i++ ) { @@ -725,17 +736,6 @@ type: "numeric" } ); - ts.addParser( { - id: "number", - is: function ( s, table ) { - return $.tablesorter.numberRegex.test( $.trim(s )); - }, - format: function (s) { - return $.tablesorter.formatDigit(s); - }, - type: "numeric" - } ); - ts.addParser( { id: "currency", is: function (s) { @@ -842,4 +842,15 @@ }, type: "numeric" } ); + ts.addParser( { + id: "number", + is: function ( s, table ) { + return $.tablesorter.numberRegex.test( $.trim(s )); + }, + format: function (s) { + return $.tablesorter.formatDigit(s); + }, + type: "numeric" + } ); + } )( jQuery ); \ No newline at end of file