tablesorterプラグインを使用して、独自のパーサーの作成に関するドキュメントを参照する必要があります。ここでそれを参照してください:http://tablesorter.com/docs/example-parsers.html
あなたが求めているものは、ドキュメントで使用されている例にほぼ正確に適合しているようです。便宜上、ドキュメントのコードを以下にコピーします。
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'grades',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return s.toLowerCase().replace(/good/,2).replace(/medium/,1).replace(/bad/,0);
},
// set type, either numeric or text
type: 'numeric'
});
$(function() {
$("table").tablesorter({
headers: {
6: {
sorter:'grades'
}
}
});
});
あなたの目的のために、コードは次のようになります:
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'medals',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
// Note the 'i' added after the medal type, that makes it case insensitive.
return s.toLowerCase().replace(/gold/i,2).replace(/silver/i,1).replace(/bronze/i,0);
},
// set type, either numeric or text
type: 'numeric'
});
$(function() {
$("table").tablesorter({
headers: {
6: { // Replace '6' with the number of the column that your medals are in
sorter:'medals'
}
}
});
});