【问题标题】:DataTables localeCompare sorting, can't get it to workDataTables localeCompare 排序,不能让它工作
【发布时间】:2015-08-01 18:30:14
【问题描述】:

我不是程序员,但我可以将一些代码放在一起使其工作。我在这个问题上挣扎了好几个小时。我在 DataTables jQuery 插件中对非 ascii 字符进行排序时遇到问题。在 DataTables 网站上找到应该使其工作的代码。但事实并非如此。我会很感激帮助我调试。我已将此代码放在标题中:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"polish-string-asc" : function (s1, s2) {
    return s1.localeCompare(s2);
},

"polish-string-desc" : function (s1, s2) {
    return s2.localeCompare(s1);
}
} );

这就是我运行表格的方式:

$(document).ready( function () {
$('#myTable').DataTable( {
      "autoWidth": false,
      "columns": [
null,
null,
{ "orderable": false },
{ "orderable": false }
  ],
columnDefs: [
{ type: 'polish-string', targets: 1 }
  ],
});
});

脚本在默认排序下运行良好。问题是它不适用于这个排序插件。

我在 WordPress 中使用 DataTables。

Chrome 给了我这个:“Uncaught TypeError: Cannot read property 'oSort' of undefined”。

FireFox 给了我这个:“TypeError: jQuery.fn.dataTableExt is undefined”。

请帮我调试一下。谢谢。

【问题讨论】:

  • 检查是否在上述代码所在的脚本之前加载了数据表脚本,或者尝试获取有问题的 jsfiddle 示例。
  • 它看起来可以在 jsfiddle.net/rt9ftxo8/11 上工作,但在我的 Wordpress 页面上却不行。可能是什么问题?
  • @Bla - “可能是什么问题?”将脚本封装在onload 中的小提琴,而您的wordpress 在到达代码后立即将其关闭。将其包装成$(document).ready(function() { ..]);

标签: javascript jquery wordpress jquery-plugins jquery-datatables


【解决方案1】:

DataTables 脚本位于页脚中。它应该首先加载。

td 中的

href 标签搞砸了。删除 href 有帮助。感谢您的提示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多