@@ -180,8 +180,9 @@ $.tablesorter.addWidget({
180
180
format : function ( table ) {
181
181
if ( ! $ ( table ) . hasClass ( 'hasFilters' ) ) {
182
182
var i , j , k , l , cv , v , val , r , ff , t , x , xi , cr ,
183
- sel , $tb , $tr , $td , reg2 ,
183
+ sel , $tb , $th , $ tr, $td , reg2 ,
184
184
c = table . config ,
185
+ $ths = $ ( c . headerList ) ,
185
186
wo = c . widgetOptions ,
186
187
css = wo . filter_cssFilter || 'tablesorter-filter' ,
187
188
$t = $ ( table ) . addClass ( 'hasFilters' ) ,
@@ -245,18 +246,14 @@ $.tablesorter.addWidget({
245
246
}
246
247
// Look for quotes to get an exact match
247
248
} else if ( / [ \" | \' ] $ / . test ( val ) && xi === val . replace ( / ( \" | \' ) / g, '' ) ) {
248
- r = ( r ) ? true : false ;
249
+ ff = true ;
249
250
// Look for wild card: ? = single, or * = multiple
250
251
} else if ( / [ \? | \* ] / . test ( val ) ) {
251
252
ff = new RegExp ( val . replace ( / \? / g, '\\S{1}' ) . replace ( / \* / g, '\\S*' ) ) . test ( xi ) ;
252
253
// Look for match, and add child row data for matching
253
254
} else {
254
255
x = ( xi + t ) . indexOf ( val ) ;
255
- if ( ( ! wo . filter_startsWith && x >= 0 ) || ( wo . filter_startsWith && x === 0 ) ) {
256
- r = ( r ) ? true : false ;
257
- } else {
258
- r = false ;
259
- }
256
+ ff = ( ( ! wo . filter_startsWith && x >= 0 ) || ( wo . filter_startsWith && x === 0 ) ) ;
260
257
}
261
258
r = ( ff ) ? ( r ? true : false ) : false ;
262
259
}
@@ -275,7 +272,7 @@ $.tablesorter.addWidget({
275
272
buildSelect = function ( i ) {
276
273
var o , arry = [ ] ;
277
274
i = parseInt ( i , 10 ) ;
278
- o = '<option value="">' + ( $ ( c . headerList [ i ] ) . attr ( 'data-placeholder' ) || '' ) + '</option>' ;
275
+ o = '<option value="">' + ( $ths . filter ( '[data-column="' + i + '"]:last' ) . attr ( 'data-placeholder' ) || '' ) + '</option>' ;
279
276
for ( k = 0 ; k < b . length ; k ++ ) {
280
277
l = c . cache [ k ] . row . length ;
281
278
// loop through the rows
@@ -291,26 +288,27 @@ $.tablesorter.addWidget({
291
288
for ( k = 0 ; k < arry . length ; k ++ ) {
292
289
o += '<option value="' + arry [ k ] + '">' + arry [ k ] + '</option>' ;
293
290
}
294
- $t . find ( 'thead' ) . find ( 'select.' + css + '[data-col ="' + i + '"]' ) . append ( o ) ;
291
+ $t . find ( 'thead' ) . find ( 'select.' + css + '[data-column ="' + i + '"]' ) . append ( o ) ;
295
292
} ;
296
293
if ( c . debug ) {
297
294
time = new Date ( ) ;
298
295
}
299
296
for ( i = 0 ; i < cols ; i ++ ) {
300
- sel = ( wo . filter_functions && wo . filter_functions [ i ] && typeof wo . filter_functions [ i ] !== 'function' ) || $ ( c . headerList [ i ] ) . hasClass ( 'filter-select' ) ;
297
+ $th = $ths . filter ( '[data-column="' + i + '"]:last' ) ; // assuming last cell of a column is the main column
298
+ sel = ( wo . filter_functions && wo . filter_functions [ i ] && typeof wo . filter_functions [ i ] !== 'function' ) || $th . hasClass ( 'filter-select' ) ;
301
299
fr += '<td>' ;
302
300
if ( sel ) {
303
- fr += '<select data-col ="' + i + '" class="' + css ;
301
+ fr += '<select data-column ="' + i + '" class="' + css ;
304
302
} else {
305
- fr += '<input type="search" placeholder="' + ( $ ( c . headerList [ i ] ) . attr ( 'data-placeholder' ) || "" ) + '" data-col ="' + i + '" class="' + css ;
303
+ fr += '<input type="search" placeholder="' + ( $th . attr ( 'data-placeholder' ) || "" ) + '" data-column ="' + i + '" class="' + css ;
306
304
}
307
305
// use header option - headers: { 1: { filter: false } } OR add class="filter-false"
308
306
if ( $ . tablesorter . getData ) {
309
307
// get data from jQuery data, metadata, headers option or header class name
310
- fr += $ . tablesorter . getData ( c . headerList [ i ] , c . headers [ i ] , 'filter' ) === 'false' ? ' disabled" disabled' : '"' ;
308
+ fr += $ . tablesorter . getData ( $th [ 0 ] , c . headers [ i ] , 'filter' ) === 'false' ? ' disabled" disabled' : '"' ;
311
309
} else {
312
310
// only class names and header options - keep this for compatibility with tablesorter v2.0.5
313
- fr += ( ( c . headers [ i ] && c . headers [ i ] . hasOwnProperty ( 'filter' ) && c . headers [ i ] . filter === false ) || $ ( c . headerList [ i ] ) . hasClass ( 'filter-false' ) ) ? ' disabled" disabled' : '"' ;
311
+ fr += ( ( c . headers [ i ] && c . headers [ i ] . hasOwnProperty ( 'filter' ) && c . headers [ i ] . filter === false ) || $th . hasClass ( 'filter-false' ) ) ? ' disabled" disabled' : '"' ;
314
312
}
315
313
fr += ( sel ? '></select>' : '>' ) + '</td>' ;
316
314
}
@@ -336,7 +334,7 @@ $.tablesorter.addWidget({
336
334
if ( wo . filter_functions ) {
337
335
// i = column # (string)
338
336
for ( i in wo . filter_functions ) {
339
- t = $ ( c . headerList [ i ] ) ;
337
+ t = $ths . filter ( '[data-column="' + i + '"]:last' ) ;
340
338
fr = '' ;
341
339
if ( typeof i === 'string' && wo . filter_functions [ i ] === true && ! t . hasClass ( 'filter-false' ) ) {
342
340
buildSelect ( i ) ;
@@ -348,13 +346,13 @@ $.tablesorter.addWidget({
348
346
fr += '<option>' + j + '</option>' ;
349
347
}
350
348
}
351
- $t . find ( 'thead' ) . find ( 'select.' + css + '[data-col ="' + i + '"]' ) . append ( fr ) ;
349
+ $t . find ( 'thead' ) . find ( 'select.' + css + '[data-column ="' + i + '"]' ) . append ( fr ) ;
352
350
}
353
351
}
354
352
}
355
353
// build default select dropdown
356
- for ( i = 0 ; i < c . headerList . length ; i ++ ) {
357
- t = $ ( c . headerList [ i ] ) ;
354
+ for ( i = 0 ; i < cols ; i ++ ) {
355
+ t = $ths . filter ( '[data-column="' + i + '"]:last' ) ;
358
356
// look for the filter-select class, but don't build it twice.
359
357
if ( t . hasClass ( 'filter-select' ) && ! t . hasClass ( 'filter-false' ) && ! ( wo . filter_functions && wo . filter_functions [ i ] === true ) ) {
360
358
buildSelect ( i ) ;
0 commit comments