Tablesorter 特定排序与法国数字

Tablesorter specific sort with french number

我正在使用 tablesorter 对不同类型的数字和字符串进行排序,但在这个数字中我有这样的数字:(带逗号和 space)

200,08€
1 201,56€
1 521 120,00€

我一定是

1 521 120,00€
1 201,56€
200,08€

和逆。

我试试解析器:

$.tablesorter.addParser({
  id: "colcpl",
  is: function(s) {
    return /^[0-9]?[0-9, \.]*$/.test(s);
  },
  format: function(s) {
    return jQuery.tablesorter.formatFloat(s.replace(/,/g, ''));
  },
  type: "numeric"
});

但它不起作用,您知道为什么吗? 非常感谢!

解析器有两个问题:(1) 逗号应替换为小数点,(2) 空格需要删除。

试试这个更新 (demo)

$(function() {

  $.tablesorter.addParser({
    id: "colcpl",
    is: function(s) {
      return /^[0-9]?[0-9, \.]*$/.test(s);
    },
    format: function(s) {
      return jQuery.tablesorter.formatFloat(s.replace(/\s/g, '').replace(/,/g, '.'));
    },
    type: "numeric"
  });

  $('table').tablesorter({
    sortList: [[0,1]],
    headers: {
      0: { sorter: 'colcpl' }
    }
  });

});