因此,我使用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
谁能帮助?
干杯
你能详细阐述一下吗?你提到“我改变了这个并解决了它”,但你改变了什么? – Kiran 2016-02-29 23:36:13