这是工作。内部缓存中的“z”已被替换。
尽管您可能需要包含一个true
标志来执行深度扩展:
$.extend( true, $.tablesorter.characterEquivalents, { ... });
查看此演示(排序以查看 firebug 窗口中的列值):http: //jsfiddle.net/Gk43v/19/
更新:好的,问题似乎是实际的排序顺序。问题是默认排序是使用字符的 ASCII 值完成的,因此 Š 和 Ž 在 AZ 之后排序,没有任何字符等效替换。该函数将“Š”替换为“S”,将“Ž”替换为“Z”,使它们与未重读的字母等效且无法区分。
如果您确实希望排序保持字符顺序,则需要使用不同的文本排序器,例如Sugarjs,它允许您设置排序顺序:
Array.AlphanumericSortOrder = 'AaÁáBbCcDdÐðEeÉéĘęFfGgHhIiÍíJjKkLlMmNnOoÓóPpQqRrSsTtUuÚúVvWwXxYyÝýZzÞþÆæÖö';
然后,您可以使用该textSorter
选项对该列使用糖数组排序 -这是一个显示冰岛排序的演示
$("table").tablesorter({
theme : 'blue',
ignoreCase : false,
textSorter : {
// alphanumeric sort from sugar (http://sugarjs.com/arrays#sorting)
// for the first column (zero-based index)
0 : Array.AlphanumericSort
}
});
更新 #2:因为捷克字母有点复杂,所以您需要将“CH”替换为占位符,因为 Sugar 在排序顺序定义中只允许单个字符。
所以在这个例子中,我用“Æ”替换了“CH”(更新了演示)
$(function () {
Array.AlphanumericSortOrder = 'AaÁáÄäBbCcČčDdĎďEeÉéĚěFfGgHhÆæIiÍíJjKkLlMmNnŇňOoÓóÖöPpQqRrŘřSsŠšTtŤťUuÚúŮůÜüVvWwXxYyÝýZzŽž';
Array.AlphanumericSortIgnoreCase = true;
// see https://github.com/andrewplummer/Sugar/issues/382#issuecomment-41526957
Array.AlphanumericSortEquivalents = {};
// replace "Ch" and "ch" with a placeholder... it can be anything
// in this example, I'm replacing ch with "æ" and Ch or CH with "Æ"
// these characters have been added to the Array.AlphanumericSortOrder
// between "h" and "I" - according to http://en.wikipedia.org/wiki/Czech_orthography
var replaceCH = function( node ) {
return $(node).text()
.replace(/(Ch|CH)/g, '\u00c6')
.replace(/ch/g, '\u00e6');
};
$("table").tablesorter({
theme: 'blue',
// table = table object; get config options from table.config
// column is the column index (zero-based)
ignoreCase: false,
textExtraction : {
1: replaceCH,
3: replaceCH
},
textSorter: {
1 : Array.AlphanumericSort, // alphanumeric sort from sugar (http://sugarjs.com/arrays#sorting)
3 : Array.AlphanumericSort
}
});
});
我确实尝试使用该characterEquivalents
函数来替换字符串,但它目前也只支持单个字符替换(我将在未来的版本中解决这个问题),所以现在我使用的是自定义textExtraction
函数。
您报告的第二个问题可以通过在 ajax 调用完成并呈现表后触发表上的“更新”方法来解决。
$('table').trigger('update');