【发布时间】:2013-02-13 16:24:09
【问题描述】:
所以我使用Datatables 插件 (http://datatables.net/) 对我的表中的数据进行排序。
我存储的数据包括数字 (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
谁能帮忙?
干杯
【问题讨论】:
标签: javascript jquery datatables