I use the latest Datatables plugin 1.10 version.
I have 3 columns (0 , 1, 2). Columns 1 and 2 contain numbers which should be formatted like:
1000 -> 1.000
10000 -> 10.000
I searched the documentation and I found these relevant functions:
https://datatables.net/reference/option/formatNumber
https://datatables.net/reference/option/language.thousands
Are the columns that need to be formatted detected automatically?
What is the correct usage of the above functions?
There is actually an even easier way to do this, also found on the datatables documentation:
"columns": [
{ "data": "ReceiptQuantity", render: $.fn.dataTable.render.number(',', '.', 2, '') },
{ "data": "ReceiptPrice", render: $.fn.dataTable.render.number(',', '.', 2, '') },
{ "data": "LineTotal", render: $.fn.dataTable.render.number(',', '.', 2, '') }
],
$('#table-dg').dataTable({
"columns": columnNames,
"columnDefs": [
{
"render": function (data, type, row) {
return commaSeparateNumber(data);
},
"targets": [1,2]
},
]
});
function commaSeparateNumber(val) {
while (/(\d+)(\d{3})/.test(val.toString())) {
val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
}
return val;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With