Reputation: 63
I'm currently working with a tablesorter table in which I need to use a custom parser for each header. I'd like to know if there's an easy way to do this, such as:
table.tablesorter({
headers: {
0-20: {
sorter:'CareerLast'
},
}
});
I know that the above code doesn't work, but I'm just wondering if there's a more readable way of applying the custom parser, other than manually placing it on each column by index.
Upvotes: 2
Views: 1400
Reputation: 56
return true from 'is' in addParser
eg: this parser assigns 'N/A' a value of -1
$.tablesorter.addParser({
id: 'num-with-na',
is: function(s) {
//always use this
return true;
},
format: function(n){
return n === 'N/A' ? -1 : n;
},
type: 'numeric'
});
Upvotes: 0
Reputation: 86413
Well, I think you have three choices:
Define each header, 0 through 20 in the initialization options.
header : {
0 : { sorter : 'CareerLast' },
1 : { sorter : 'CareerLast' },
2 : { sorter : 'CareerLast' },
// etc
20 : { sorter : 'CareerLast' }
}
Use the meta data plugin and add the sorter definition in the header class:
// untested, but I think this will work
$('table').find('thead th').addClass("{sorter:'CareerLast'}");
$('table').tablesorter();
Try out my forked version of tablesorter and just add the sorter as a class name
$('table').find('thead th').addClass('sorter-CareerLast');
$('table').tablesorter();
Upvotes: 4