Javascript DataTables-插件问题

Javascript DataTables - Plugins Issue

本文关键字:问题 插件 DataTables- Javascript      更新时间:2023-09-26

所以我使用的是Datatables插件(http://datatables.net/)对表中的数据进行排序。

我存储的数据包括数字(22.34)、货币(223400美元)和格式化数字(233623)。网站上有一个插件排序部分(http://datatables.net/plug-ins/sorting)。

在过去的两个小时里,我一直在努力让它发挥作用,但无论我做什么,都会不断出错。

这是我的代码:

包括以下脚本:

<script src="assets/js/dataTables.plugins.js"></script> 

包含以下内容:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function ( a ) {
    a = (a==="-") ? 0 : a.replace( /[^'d'-'.]/g, "" );
    return parseFloat( a );
},
"formatted-num-asc": function ( a, b ) {
    return a - b;
},
"formatted-num-desc": function ( a, b ) {
    return b - a;
}
} );

然后主代码:

<script>   
    $(document).ready(function() {
     var oTable = $('#sample_1').dataTable( {
            "sDom": "<'row-fluid'<'span4'l><'span4 tbl_time_frame'><'span4'f>r>t<'row-fluid'<'span4'i><'span4'><'span4'p>>",
            "sPaginationType": "bootstrap",
            "aoColumns": [
               { "sType": "numeric"  },
               null,
               { "sType": "formatted-num"},
               { "sType": "numeric"},
               null,
               null,
               null,
               null,
               null
             ],
            "oLanguage": {
                "sLengthMenu": "_MENU_ records per page",
                "oPaginate": {
                    "sPrevious": "Prev",
                    "sNext": "Next"
                }
            },
            "fnInitComplete": jQuery('.tooltips').tooltip()
     });
});

我在页面加载上有以下错误:

Uncaught TypeError: Cannot read property 'oSort' of undefined 

然后,当我点击第三行时,我交替出现以下错误:

Uncaught TypeError: Property 'formatted-num-asc' of object #<Object> is not a function jquery.dataTables.js:4038
Uncaught TypeError: Property 'formatted-num-desc' of object #<Object> is not a function 

有人能帮忙吗?

干杯

问题在于文件的包含顺序。我改变了这个,它解决了问题。

当我将naturalSort.js与dataTables.js一起使用时,在试图解决同样的问题时,我刚刚遇到了这篇旧文章。对我来说,有效的方法是将naturalSort.js移到dataTables.js之后。简单的更改,但解决了问题。