Jquery datatables format numbers
$('#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;
}
As mentioned in my comment you have to do something like this
Inside Datatable initialization :
"aoColumnDefs": [ {
"aTargets": [ 2 ],
"mRender": function (data, type, full) {
var formmatedvalue=data.replace(//regex expression)
return formmatedvalue;
}
}]
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, '') }
],