2

Hi have wrote tablesorter plugin to sort Polish chars but plugin sorts just one way http://jsfiddle.net/Gk43v/ here is the example and plugin code

$.tablesorter.addParser({
   id: 'polish-chars' ,
   type: 'text',
   is: function(s)
   {
       return false;
   },
   format: function(s)
   {
       return
       s.replace('\u0105'/g, 'a')
       .replace('\u0104'/g, 'A')
       .replace('\u0118'/g, 'E')
       .replace('\u0119'/g, 'e')
       .replace('\u0107'/g, 'c')
       .replace('\u0106'/g, 'C')
       .replace('\u0143'/g, 'N')
       .replace('\u0144'/g, 'n')
       .replace('Ó'/g, 'O')
       .replace('ó'/g, 'o')
       .replace('\u0141'/g, 'L')
       .replace('\u0142'/g, 'l')
       .replace('\u015a'/g, 'S')
       .replace('\u015b'/g, 's')
       .replace('\u0179'/g, 'Z')
       .replace('\u017a'/g, 'z')
       .replace('\u017b'/g, 'Z')
       .replace('\u017c'/g, 'z')
   }
});

Edit: When using this plugin with tablesorter it didn't show an error /g, so it should look like

$.tablesorter.addParser({
   id: 'polish-chars',
   type: 'text',
   is: function(s)
   {
       return false;
   },
   format: function(s)
   {
       return s.replace('ą', 'a')
               .replace('Ą', 'A')
               .replace('Ę', 'E')
               .replace('ę', 'e')
               .replace('ć', 'c')
               .replace('Ć', 'C')
               .replace('Ń', 'N')
               .replace('ń', 'n')
               .replace('Ó', 'O')
               .replace('ó', 'o')
               .replace('Ł', 'L')
               .replace('ł', 'l')
               .replace('Ś', 'S')
               .replace('ś', 's')
               .replace('Ź', 'Z')
               .replace('ź', 'z')
               .replace('Ż', 'Z')
               .replace('ż', 'z');
   }
});

and work just like I wanted to work.

4

1 回答 1

2

使用 replace with 时/g,不要使用引号(更新的演示):

$.tablesorter.addParser({
    id: 'polish-chars',
    type: 'text',
    is: function(s) {
        return false;
    },
    format: function(s) {
       return s.replace(/\u0105/g, 'a')
       .replace(/\u0104/g, 'A')
       .replace(/\u0118/g, 'E')
       .replace(/\u0119/g, 'e')
       .replace(/\u0107/g, 'c')
       .replace(/\u0106/g, 'C')
       .replace(/\u0143/g, 'N')
       .replace(/\u0144/g, 'n')
       .replace(/Ó/g, 'O')
       .replace(/ó/g, 'o')
       .replace(/\u0141/g, 'L')
       .replace(/\u0142/g, 'l')
       .replace(/\u015a/g, 'S')
       .replace(/\u015b/g, 's')
       .replace(/\u0179/g, 'Z')
       .replace(/\u017a/g, 'z')
       .replace(/\u017b/g, 'Z')
       .replace(/\u017c/g, 'z');
    }
});

另外,您可以尝试我的tablesorter叉子,该叉子在选项为时进行字符等效替换。只需将缺少的波兰语字符添加到列表中:sortLocaleComparetrue

$.extend( $.tablesorter.characterEquivalents, {
    "a" : "\u0105", // ą
    "A" : "\u0104", // Ą
    "c" : "\u0107", // ć
    "C" : "\u0106", // Ć
    "e" : "\u0119", // ę
    "E" : "\u0118", // Ę
    "l" : "\u0142", // ł
    "L" : "\u0141", // Ł
    "n" : "\u0144", // ń
    "N" : "\u0143", // Ń
    "o" : "\u00f3", // ó
    "O" : "\u00d3", // Ó
    "s" : "\u015b", // ś
    "S" : "\u015a", // Ś
    "z" : "\u017a\u017c", // źż
    "Z" : "\u0179\u017b" // ŹŻ
});
于 2012-05-30T19:46:57.023 回答