mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
parent
c7d4395c85
commit
55d19b3a95
@ -253,7 +253,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function buildParserCache( c, $tbodies ) {
|
function buildParserCache( c, $tbodies ) {
|
||||||
var rows, list, l, i, h, ch, np, p, e, time, tb, len,
|
var rows, list, span, max, colIndex, i, h, ch, np, p, e, time, tb, len,
|
||||||
table = c.table,
|
table = c.table,
|
||||||
j = 0,
|
j = 0,
|
||||||
debug = {};
|
debug = {};
|
||||||
@ -274,19 +274,21 @@
|
|||||||
while (j < len) {
|
while (j < len) {
|
||||||
rows = tb[j].rows;
|
rows = tb[j].rows;
|
||||||
if (rows.length) {
|
if (rows.length) {
|
||||||
l = c.columns; // rows[j].cells.length;
|
colIndex = 0;
|
||||||
for (i = 0; i < l; i++) {
|
max = c.columns; // rows[j].cells.length;
|
||||||
h = c.$headerIndexed[i];
|
for (i = 0; i < max; i++) {
|
||||||
|
h = c.$headerIndexed[ colIndex ];
|
||||||
|
if ( h && h.length ) {
|
||||||
// get column indexed table cell
|
// get column indexed table cell
|
||||||
ch = ts.getColumnData( table, c.headers, i );
|
ch = ts.getColumnData( table, c.headers, colIndex );
|
||||||
// get column parser/extractor
|
// get column parser/extractor
|
||||||
e = ts.getParserById( ts.getData(h, ch, 'extractor') );
|
e = ts.getParserById( ts.getData(h, ch, 'extractor') );
|
||||||
p = ts.getParserById( ts.getData(h, ch, 'sorter') );
|
p = ts.getParserById( ts.getData(h, ch, 'sorter') );
|
||||||
np = ts.getData(h, ch, 'parser') === 'false';
|
np = ts.getData(h, ch, 'parser') === 'false';
|
||||||
// empty cells behaviour - keeping emptyToBottom for backwards compatibility
|
// empty cells behaviour - keeping emptyToBottom for backwards compatibility
|
||||||
c.empties[i] = ( ts.getData(h, ch, 'empty') || c.emptyTo || (c.emptyToBottom ? 'bottom' : 'top' ) ).toLowerCase();
|
c.empties[colIndex] = ( ts.getData(h, ch, 'empty') || c.emptyTo || (c.emptyToBottom ? 'bottom' : 'top' ) ).toLowerCase();
|
||||||
// text strings behaviour in numerical sorts
|
// text strings behaviour in numerical sorts
|
||||||
c.strings[i] = ( ts.getData(h, ch, 'string') || c.stringTo || 'max' ).toLowerCase();
|
c.strings[colIndex] = ( ts.getData(h, ch, 'string') || c.stringTo || 'max' ).toLowerCase();
|
||||||
if (np) {
|
if (np) {
|
||||||
p = ts.getParserById('no-parser');
|
p = ts.getParserById('no-parser');
|
||||||
}
|
}
|
||||||
@ -298,15 +300,22 @@
|
|||||||
p = detectParserForColumn(c, rows, -1, i);
|
p = detectParserForColumn(c, rows, -1, i);
|
||||||
}
|
}
|
||||||
if (c.debug) {
|
if (c.debug) {
|
||||||
debug[ '(' + i + ') ' + h.text() ] = {
|
debug[ '(' + colIndex + ') ' + h.text() ] = {
|
||||||
parser : p.id,
|
parser : p.id,
|
||||||
extractor : e ? e.id : 'none',
|
extractor : e ? e.id : 'none',
|
||||||
string : c.strings[i],
|
string : c.strings[colIndex],
|
||||||
empty : c.empties[i]
|
empty : c.empties[colIndex]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
list.parsers[i] = p;
|
list.parsers[colIndex] = p;
|
||||||
list.extractors[i] = e;
|
list.extractors[colIndex] = e;
|
||||||
|
span = h[0].colSpan - 1;
|
||||||
|
if ( span > 0 ) {
|
||||||
|
colIndex += span;
|
||||||
|
max += span;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
colIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j += (list.parsers.length) ? len : 1;
|
j += (list.parsers.length) ? len : 1;
|
||||||
@ -326,8 +335,8 @@
|
|||||||
|
|
||||||
/* utils */
|
/* utils */
|
||||||
function buildCache(table, callback, $tbodies) {
|
function buildCache(table, callback, $tbodies) {
|
||||||
var cc, t, v, i, j, k, $tb, $row, cols, cacheTime,
|
var cc, t, v, i, j, k, $tb, $row, cols, cell, cacheTime,
|
||||||
totalRows, rowData, prevRowData, colMax,
|
totalRows, rowData, prevRowData, colMax, span, cacheIndex, max,
|
||||||
c = table.config,
|
c = table.config,
|
||||||
parsers = c.parsers;
|
parsers = c.parsers;
|
||||||
// update tbody variable
|
// update tbody variable
|
||||||
@ -379,29 +388,52 @@
|
|||||||
t = prevRowData.child.length;
|
t = prevRowData.child.length;
|
||||||
prevRowData.child[ t ] = [];
|
prevRowData.child[ t ] = [];
|
||||||
// child row content does not account for colspans/rowspans; so indexing may be off
|
// child row content does not account for colspans/rowspans; so indexing may be off
|
||||||
for ( j = 0; j < c.columns; j++ ) {
|
cacheIndex = 0;
|
||||||
prevRowData.child[ t ][ j ] = ts.getParsedText( c, v[ j ], j );
|
max = c.columns;
|
||||||
|
for ( j = 0; j < max; j++ ) {
|
||||||
|
cell = v[ j ];
|
||||||
|
if ( cell ) {
|
||||||
|
prevRowData.child[ t ][ j ] = ts.getParsedText( c, cell, j );
|
||||||
|
span = v[ j ].colSpan - 1;
|
||||||
|
if ( span > 0 ) {
|
||||||
|
cacheIndex += span;
|
||||||
|
max += span
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cacheIndex++;
|
||||||
}
|
}
|
||||||
// go to the next for loop
|
// go to the next for loop
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
rowData.$row = $row;
|
rowData.$row = $row;
|
||||||
rowData.order = i; // add original row position to rowCache
|
rowData.order = i; // add original row position to rowCache
|
||||||
for ( j = 0; j < c.columns; ++j ) {
|
cacheIndex = 0;
|
||||||
if (typeof parsers[ j ] === 'undefined') {
|
max = c.columns;
|
||||||
|
for ( j = 0; j < max; ++j ) {
|
||||||
|
cell = $row[ 0 ].cells[ j ];
|
||||||
|
if ( cell ) {
|
||||||
|
if (typeof parsers[ cacheIndex ] === 'undefined') {
|
||||||
if ( c.debug ) {
|
if ( c.debug ) {
|
||||||
console.warn( 'No parser found for cell:', $row[ 0 ].cells[ j ], 'does it have a header?' );
|
console.warn( 'No parser found for cell:', cell, 'does it have a header?' );
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
t = ts.getElementText( c, $row[ 0 ].cells[j], j );
|
t = ts.getElementText( c, cell, cacheIndex );
|
||||||
rowData.raw.push( t ); // save original row text
|
rowData.raw[ cacheIndex ] = t; // save original row text
|
||||||
v = ts.getParsedText( c, $row[ 0 ].cells[ j ], j, t );
|
v = ts.getParsedText( c, cell, cacheIndex, t );
|
||||||
cols.push( v );
|
cols[ cacheIndex ] = v;
|
||||||
if ( ( parsers[ j ].type || '' ).toLowerCase() === 'numeric' ) {
|
if ( ( parsers[ cacheIndex ].type || '' ).toLowerCase() === 'numeric' ) {
|
||||||
// determine column max value (ignore sign)
|
// determine column max value (ignore sign)
|
||||||
colMax[ j ] = Math.max( Math.abs( v ) || 0, colMax[ j ] || 0 );
|
colMax[ j ] = Math.max( Math.abs( v ) || 0, colMax[ cacheIndex ] || 0 );
|
||||||
}
|
}
|
||||||
|
// allow colSpan in tbody
|
||||||
|
span = cell.colSpan - 1;
|
||||||
|
if ( span > 0 ) {
|
||||||
|
cacheIndex += span;
|
||||||
|
max += span;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cacheIndex++;
|
||||||
}
|
}
|
||||||
// ensure rowData is always in the same location (after the last column)
|
// ensure rowData is always in the same location (after the last column)
|
||||||
cols[ c.columns ] = rowData;
|
cols[ c.columns ] = rowData;
|
||||||
@ -487,7 +519,9 @@
|
|||||||
$t = c.$headers.filter('[data-column="' + indx + '"]');
|
$t = c.$headers.filter('[data-column="' + indx + '"]');
|
||||||
// target sortable column cells, unless there are none, then use non-sortable cells
|
// target sortable column cells, unless there are none, then use non-sortable cells
|
||||||
// .last() added in jQuery 1.4; use .filter(':last') to maintain compatibility with jQuery v1.2.6
|
// .last() added in jQuery 1.4; use .filter(':last') to maintain compatibility with jQuery v1.2.6
|
||||||
c.$headerIndexed[indx] = $t.not('.sorter-false').length ? $t.not('.sorter-false').filter(':last') : $t.filter(':last');
|
c.$headerIndexed[indx] = $t.length ?
|
||||||
|
$t.not('.sorter-false').length ? $t.not('.sorter-false').filter(':last') : $t.filter(':last') :
|
||||||
|
$();
|
||||||
}
|
}
|
||||||
c.$table.find(c.selectorHeaders).attr({
|
c.$table.find(c.selectorHeaders).attr({
|
||||||
scope: 'col',
|
scope: 'col',
|
||||||
|
@ -647,14 +647,20 @@
|
|||||||
return parsed ? c.parsers[column].format( filter, c.table, [], column ) : filter;
|
return parsed ? c.parsers[column].format( filter, c.table, [], column ) : filter;
|
||||||
},
|
},
|
||||||
buildRow: function( table, c, wo ) {
|
buildRow: function( table, c, wo ) {
|
||||||
var col, column, $header, makeSelect, disabled, name, ffxn, tmp,
|
var $filter, col, column, $header, makeSelect, disabled, name, ffxn, tmp,
|
||||||
// c.columns defined in computeThIndexes()
|
// c.columns defined in computeThIndexes()
|
||||||
cellFilter = wo.filter_cellFilter,
|
cellFilter = wo.filter_cellFilter,
|
||||||
columns = c.columns,
|
columns = c.columns,
|
||||||
arry = $.isArray( cellFilter ),
|
arry = $.isArray( cellFilter ),
|
||||||
buildFilter = '<tr role="row" class="' + tscss.filterRow + ' ' + c.cssIgnoreRow + '">';
|
buildFilter = '<tr role="row" class="' + tscss.filterRow + ' ' + c.cssIgnoreRow + '">';
|
||||||
for ( column = 0; column < columns; column++ ) {
|
for ( column = 0; column < columns; column++ ) {
|
||||||
buildFilter += '<td';
|
if ( c.$headerIndexed[ column ].length ) {
|
||||||
|
buildFilter += '<td data-column="' + column + '"';
|
||||||
|
// account for entire column set with colspan. See #1047
|
||||||
|
tmp = c.$headerIndexed[ column ] && c.$headerIndexed[ column ][0].colSpan || 0;
|
||||||
|
if ( tmp > 1 ) {
|
||||||
|
buildFilter += ' colspan="' + tmp + '"';
|
||||||
|
}
|
||||||
if ( arry ) {
|
if ( arry ) {
|
||||||
buildFilter += ( cellFilter[ column ] ? ' class="' + cellFilter[ column ] + '"' : '' );
|
buildFilter += ( cellFilter[ column ] ? ' class="' + cellFilter[ column ] + '"' : '' );
|
||||||
} else {
|
} else {
|
||||||
@ -662,14 +668,17 @@
|
|||||||
}
|
}
|
||||||
buildFilter += '></td>';
|
buildFilter += '></td>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
c.$filters = $( buildFilter += '</tr>' )
|
c.$filters = $( buildFilter += '</tr>' )
|
||||||
.appendTo( c.$table.children( 'thead' ).eq( 0 ) )
|
.appendTo( c.$table.children( 'thead' ).eq( 0 ) )
|
||||||
.find( 'td' );
|
.children( 'td' );
|
||||||
// build each filter input
|
// build each filter input
|
||||||
for ( column = 0; column < columns; column++ ) {
|
for ( column = 0; column < columns; column++ ) {
|
||||||
disabled = false;
|
disabled = false;
|
||||||
// assuming last cell of a column is the main column
|
// assuming last cell of a column is the main column
|
||||||
$header = c.$headerIndexed[ column ];
|
$header = c.$headerIndexed[ column ];
|
||||||
|
if ( $header && $header.length ) {
|
||||||
|
$filter = c.$filters.filter( '[data-column="' + column + '"]' );
|
||||||
ffxn = ts.getColumnData( table, wo.filter_functions, column );
|
ffxn = ts.getColumnData( table, wo.filter_functions, column );
|
||||||
makeSelect = ( wo.filter_functions && ffxn && typeof ffxn !== 'function' ) ||
|
makeSelect = ( wo.filter_functions && ffxn && typeof ffxn !== 'function' ) ||
|
||||||
$header.hasClass( 'filter-select' );
|
$header.hasClass( 'filter-select' );
|
||||||
@ -679,23 +688,23 @@
|
|||||||
ts.getData( $header[0], col, 'parser' ) === 'false';
|
ts.getData( $header[0], col, 'parser' ) === 'false';
|
||||||
|
|
||||||
if ( makeSelect ) {
|
if ( makeSelect ) {
|
||||||
buildFilter = $( '<select>' ).appendTo( c.$filters.eq( column ) );
|
buildFilter = $( '<select>' ).appendTo( $filter );
|
||||||
} else {
|
} else {
|
||||||
ffxn = ts.getColumnData( table, wo.filter_formatter, column );
|
ffxn = ts.getColumnData( table, wo.filter_formatter, column );
|
||||||
if ( ffxn ) {
|
if ( ffxn ) {
|
||||||
wo.filter_formatterCount++;
|
wo.filter_formatterCount++;
|
||||||
buildFilter = ffxn( c.$filters.eq( column ), column );
|
buildFilter = ffxn( $filter, column );
|
||||||
// no element returned, so lets go find it
|
// no element returned, so lets go find it
|
||||||
if ( buildFilter && buildFilter.length === 0 ) {
|
if ( buildFilter && buildFilter.length === 0 ) {
|
||||||
buildFilter = c.$filters.eq( column ).children( 'input' );
|
buildFilter = $filter.children( 'input' );
|
||||||
}
|
}
|
||||||
// element not in DOM, so lets attach it
|
// element not in DOM, so lets attach it
|
||||||
if ( buildFilter && ( buildFilter.parent().length === 0 ||
|
if ( buildFilter && ( buildFilter.parent().length === 0 ||
|
||||||
( buildFilter.parent().length && buildFilter.parent()[0] !== c.$filters[column] ) ) ) {
|
( buildFilter.parent().length && buildFilter.parent()[0] !== $filter[0] ) ) ) {
|
||||||
c.$filters.eq( column ).append( buildFilter );
|
$filter.append( buildFilter );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buildFilter = $( '<input type="search">' ).appendTo( c.$filters.eq( column ) );
|
buildFilter = $( '<input type="search">' ).appendTo( $filter );
|
||||||
}
|
}
|
||||||
if ( buildFilter ) {
|
if ( buildFilter ) {
|
||||||
tmp = $header.data( 'placeholder' ) ||
|
tmp = $header.data( 'placeholder' ) ||
|
||||||
@ -715,6 +724,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
bindSearch: function( table, $el, internal ) {
|
bindSearch: function( table, $el, internal ) {
|
||||||
table = $( table )[0];
|
table = $( table )[0];
|
||||||
@ -1261,7 +1271,7 @@
|
|||||||
// ( '> -10' => '> -100' will ignore hidden rows )
|
// ( '> -10' => '> -100' will ignore hidden rows )
|
||||||
!( regex.isNeg1.test( val ) || regex.isNeg2.test( val ) ) &&
|
!( regex.isNeg1.test( val ) || regex.isNeg2.test( val ) ) &&
|
||||||
// if filtering using a select without a 'filter-match' class ( exact match ) - fixes #593
|
// if filtering using a select without a 'filter-match' class ( exact match ) - fixes #593
|
||||||
!( val !== '' && c.$filters && c.$filters.eq( indx ).find( 'select' ).length &&
|
!( val !== '' && c.$filters && c.$filters.filter( '[data-column="' + indx + '"]' ).find( 'select' ).length &&
|
||||||
!c.$headerIndexed[indx].hasClass( 'filter-match' ) );
|
!c.$headerIndexed[indx].hasClass( 'filter-match' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user