2013-02-13 24 views
1

因此,我使用Datatables插件(http://datatables.net/)对我的表格中的数据进行排序。Javascript数据表 - 插件问题

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

我花了最近2个小时试图让这个工作,但不管我尝试什么都不断收到错误。

这里是我的代码:

包括如下脚本:

<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 

谁能帮助?

干杯

回答

2

的问题是,在这些文件中包含的顺序做。我改变了这一点,它解决了这个问题。

+0

你能详细阐述一下吗?你提到“我改变了这个并解决了它”,但你改变了什么? – Kiran 2016-02-29 23:36:13

0

我试图解决同样的问题时,通过dataTables.js使用naturalSort.js时遇到了这个旧帖子。对我来说有效的是在dataTables.js之后移动naturalSort.js。简单的改变,但解决了问题。