[英]Jquery datatables: sort number with comma doesn't work
Use numeric-comma plugin to sort numbers correctly which use a comma as the decimal place. 使用数字逗号插件正确地对数字进行排序,这些数字使用逗号作为小数位。
Either include //cdn.datatables.net/plug-ins/1.10.11/sorting/numeric-comma.js
or use it inline as shown below: 包括
//cdn.datatables.net/plug-ins/1.10.11/sorting/numeric-comma.js
或内联使用,如下所示:
$.extend( $.fn.dataTableExt.oSort, {
"numeric-comma-pre": function ( a ) {
var x = (a == "-") ? 0 : a.replace( /,/, "." );
return parseFloat( x );
},
"numeric-comma-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"numeric-comma-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
$('#test').DataTable({
columnDefs: [
{ targets: 4, type: 'numeric-comma' }
]
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.