问题
I have this table which has TableSorter plugin.
Jsbin #1
However - I want for column #1 ( second zero based) to be sorted by the first char second char as digit !)
example :
4134 (I dont care about the other digits order - just the first one which is here=1)
22230 //2
242 //4
67 //7
28 //8
992222 //9
So I created another textExtraction function : ( which is going to be applied only at the first column)
var myExtraction = function(node) {
return parseInt($(node).substring(1))
}
and added another object to the ctor which is only for column #1.(0'based).
...,{
textExtraction: myExtraction,
headers: {
1: {
sorter: 'digit'
}
}
}
However it doesn't ( jsbin#2 is here new jsbin) work and i'm pretty sure this is not the way.
Any help please?
回答1:
I'm not sure you need the custom myExtraction at all. Just change the sorter for that column to 'text' instead of 'digit' and it should work when you specify it with the rest of the headers.
Edit
If you want the second digit to be used for sorting:
var myExtraction = function(node) {
return $(node).text().substring(1);
}
jQuery('#bullsTable').tablesorter(
{
headers: {
0: {
sorter: false
},
1: {
sorter: 'text'
},
13: {
sorter: 'digit'
},
14: {
sorter: 'digit'
}
},
textExtraction: jgExtraction,
textExtraction: {
1: myExtraction
}
}
I updated your jsbin here.
Note: you were using an old version of tablesorter that didn't appear to support textExtraction. I updated the <script> tag and it works.
来源:https://stackoverflow.com/questions/14546186/tablesorter-and-multi-textextraction-in-jquery