使用tablesorter对混合数据列进行排序

我目前正在使用这里找到的JQuery Tablesorter插件: http ://www.tablesorter.com,我遇到了包含日期和文本的列的问题。 这是jsfiddle:

http://jsfiddle.net/M3V4U/1/

如果单击第一个名称字段标题,它将不会排序,因为里面有一个随机日期。 我尝试强制文本排序,但它不起作用。 有人有主意吗?

看起来您正在尝试使用元数据设置分拣机类型

first name 

但元数据插件未加载到该演示中。 因此,要么加载元数据插件 ,要么将分拣机类型添加到标头选项:

 $("table").tablesorter({ headers: { 0: { sorter: "text" }, 4: { sorter: "percent" } } }); 

这是一个更新的演示 。

找到一个不那么好的答案,但现在有效。

我删除了这个解析器:

 ts.addParser({ id: "shortDate", is: function (s) { return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s); }, format: function (s, table) { var c = table.config; s = s.replace(/\-/g, "/"); if (c.dateFormat == "us") { // reformat the string in ISO format s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2"); } else if (c.dateFormat == "uk") { // reformat the string in ISO format s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1"); } else if (c.dateFormat == "dd/mm/yy" || c.dateFormat == "dd-mm-yy") { s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$1/$2/$3"); } return $.tablesorter.formatFloat(new Date(s).getTime()); }, type: "numeric" }); 

这似乎解决了我的问题,因为它阻止日期解析器完全执行。 这可能会导致其他情况出现问题,但现在似乎适用于我的页面。 如果人们拥有它们,我仍然愿意接受任何其他答案。