JQuery data format numbers

I am using the latest version of the Datatables plugin version 1.10.

I have 3 columns (0, 1, 2). Columns 1 and 2 contain numbers that should be formatted as follows:

1000 -> 1.000 10000 -> 10.000 

I searched the documentation and I found these related functions:

https://datatables.net/reference/option/formatNumber

https://datatables.net/reference/option/language.thousands

Are the columns to be formatted automatically registered?

What is the proper use of the above functions?

+7
source share
3 answers

As mentioned in my comment, you should do something like this

Datatable internal initialization :

  "aoColumnDefs": [ { "aTargets": [ 2 ], "mRender": function (data, type, full) { var formmatedvalue=data.replace(//regex expression) return formmatedvalue; } }] 
0
source

In fact, there is an even simpler way to do this, also found in the data 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, '') } ], 
+14
source
 $('#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; } 
+3
source

Source: https://habr.com/ru/post/1208665/


All Articles