2
我想用逗號(,)以數字的數字對列進行排序。jquery數據表:用逗號分類的數字不起作用
我使用num-fmt
選項得到一個錯誤的結果:
這裏是我的代碼:
$('#test').DataTable({
columnDefs: [
{ targets: 4, type: 'num-fmt' }
]
});
我想用逗號(,)以數字的數字對列進行排序。jquery數據表:用逗號分類的數字不起作用
我使用num-fmt
選項得到一個錯誤的結果:
這裏是我的代碼:
$('#test').DataTable({
columnDefs: [
{ targets: 4, type: 'num-fmt' }
]
});
使用numeric-comma插件號碼正確,其使用逗號作爲小數排序地點。
無論是包括//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' }
]
});
工作正常!謝謝 – wawanopoulos