数据分类数字不工作 [英] Datatable sort numbers dont work
本文介绍了数据分类数字不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的网站上有一个数据表,尝试用1,999,999,999对数字进行排序,但是它不起作用。我试图解决这个问题,并提供了很多关于Google的提示,但并没有帮助我。
I have a datatable on my website and try to sort numbers with 1,999,999,999 but it doesn't work. I tried to fix the problem with a lot of tips on Google but it does not helped me.
这是我表的JavaScript代码
Thats the javascript code for my table
$('.d3uitems').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": '<""l>t<"F"p>',
'aaSorting': [[ 0, 'desc' ]]
}).columnFilter({
aoColumns: [ null,
{ type: "text"},
null,
null,
{ type: "text"},
null
]
});
这是Datatable我试图排序数字。
Here is the Datatable where i try to sort the numbers.
http://www.lootfinder.net/index.php?page = d3uitems
推荐答案
可以尝试一下,我们覆盖DataTable排序函数,并替换,。 p>
You can try it, we overwrite DataTable sort function, and replace ",".
<script type="text/javascript" charset="utf-8">
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/g,"" );
var y = (b == "-") ? 0 : b.replace( /,/g,"" );
alert( "x=" + x );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( ",","" );
var y = (b == "-") ? 0 : b.replace( ",","" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#example').dataTable( {
"sPaginationType": "full_numbers",
"bPaginate": false,
"aoColumns": [
null,
null,
null,
{ "sType": "numeric-comma" },
null
]
} );
} );
</script>
这篇关于数据分类数字不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文