Index: trunk/phase3/resources/jquery/jquery.tablesorter.js |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | } |
110 | 110 | |
111 | 111 | if (p === false) { |
112 | | - p = detectParserForColumn( table, rows, -1, i ); |
| 112 | + p = detectParserForColumn( table, rows, i ); |
113 | 113 | } |
114 | 114 | // if ( table.config.debug ) { |
115 | 115 | // console.log( "column:" + i + " parser:" + p.id + "\n" ); |
— | — | @@ -119,40 +119,51 @@ |
120 | 120 | return list; |
121 | 121 | } |
122 | 122 | |
123 | | - function detectParserForColumn( table, rows, rowIndex, cellIndex ) { |
| 123 | + function detectParserForColumn( table, rows, cellIndex ) { |
124 | 124 | var l = parsers.length, |
125 | | - node = false, |
126 | | - nodeValue = false, |
127 | | - keepLooking = true; |
128 | | - while ( nodeValue == '' && keepLooking ) { |
129 | | - rowIndex++; |
130 | | - if ( rows[rowIndex] ) { |
131 | | - node = getNodeFromRowAndCellIndex( rows, rowIndex, cellIndex ); |
132 | | - nodeValue = trimAndGetNodeText( node ); |
133 | | - // if ( table.config.debug ) { |
134 | | - // console.log( 'Checking if value was empty on row:' + rowIndex ); |
135 | | - // } |
| 125 | + nodeValue, |
| 126 | + // Start with 1 because 0 is the fallback parser |
| 127 | + i = 1, |
| 128 | + rowIndex = 0, |
| 129 | + concurrent = 0, |
| 130 | + needed = (rows.length > 4 ) ? 5 : rows.length; |
| 131 | + while( i<l ) { |
| 132 | + nodeValue = getTextFromRowAndCellIndex( rows, rowIndex, cellIndex ); |
| 133 | + if ( nodeValue != '') { |
| 134 | + if ( parsers[i].is( nodeValue, table ) ) { |
| 135 | + concurrent++; |
| 136 | + rowIndex++; |
| 137 | + if (concurrent >= needed ) { |
| 138 | + // Confirmed the parser for multiple cells, let's return it |
| 139 | + return parsers[i]; |
| 140 | + } |
| 141 | + } else { |
| 142 | + // Check next parser, reset rows |
| 143 | + i++; |
| 144 | + rowIndex = 0; |
| 145 | + } |
136 | 146 | } else { |
137 | | - keepLooking = false; |
| 147 | + // Empty cell |
| 148 | + rowIndex++; |
| 149 | + if ( rowIndex > rows.length ) { |
| 150 | + rowIndex = 0; |
| 151 | + i++; |
| 152 | + } |
138 | 153 | } |
139 | 154 | } |
140 | | - for ( var i = 1; i < l; i++ ) { |
141 | | - if ( parsers[i].is( nodeValue, table, node ) ) { |
142 | | - return parsers[i]; |
143 | | - } |
144 | | - } |
| 155 | + |
145 | 156 | // 0 is always the generic parser ( text ) |
146 | 157 | return parsers[0]; |
147 | 158 | } |
148 | | - |
149 | | - function getNodeFromRowAndCellIndex( rows, rowIndex, cellIndex ) { |
150 | | - return rows[rowIndex].cells[cellIndex]; |
| 159 | + |
| 160 | + function getTextFromRowAndCellIndex( rows, rowIndex, cellIndex ) { |
| 161 | + if ( rows[rowIndex] && rows[rowIndex].cells[cellIndex] ) { |
| 162 | + return $.trim( getElementText( rows[rowIndex].cells[cellIndex] ) ); |
| 163 | + } else { |
| 164 | + return ''; |
| 165 | + } |
151 | 166 | } |
152 | | - |
153 | | - function trimAndGetNodeText( node ) { |
154 | | - return $.trim( getElementText( node ) ); |
155 | | - } |
156 | | - |
| 167 | + |
157 | 168 | function getParserById( name ) { |
158 | 169 | var l = parsers.length; |
159 | 170 | for ( var i = 0; i < l; i++ ) { |
— | — | @@ -726,17 +737,6 @@ |
727 | 738 | } ); |
728 | 739 | |
729 | 740 | ts.addParser( { |
730 | | - id: "number", |
731 | | - is: function ( s, table ) { |
732 | | - return $.tablesorter.numberRegex.test( $.trim(s )); |
733 | | - }, |
734 | | - format: function (s) { |
735 | | - return $.tablesorter.formatDigit(s); |
736 | | - }, |
737 | | - type: "numeric" |
738 | | - } ); |
739 | | - |
740 | | - ts.addParser( { |
741 | 741 | id: "currency", |
742 | 742 | is: function (s) { |
743 | 743 | return ts.rgx.currency[0].test(s); |
— | — | @@ -842,4 +842,15 @@ |
843 | 843 | }, |
844 | 844 | type: "numeric" |
845 | 845 | } ); |
| 846 | + ts.addParser( { |
| 847 | + id: "number", |
| 848 | + is: function ( s, table ) { |
| 849 | + return $.tablesorter.numberRegex.test( $.trim(s )); |
| 850 | + }, |
| 851 | + format: function (s) { |
| 852 | + return $.tablesorter.formatDigit(s); |
| 853 | + }, |
| 854 | + type: "numeric" |
| 855 | + } ); |
| 856 | + |
846 | 857 | } )( jQuery ); |
\ No newline at end of file |