DataTables replace point with comma

0

I am working with DataTables and a problem has arisen with the rendering of decimals, according to the documentation of < a href="https://datatables.net/manual/data/renderers#Number-helper"> render would be done as follows:

{
    data: 'ejemplo',
    render: $.fn.dataTable.render.number( '.', ',', 2)
}

My idea is to have 2 decimals after the comma, so up there we go well, the problem is given, when in the same column ejemplo I have integers, I have information like the following

Dato del back-end|Obtenido en DataTable|Dato Pretendido
10.11            |10,11                |10,11 
15               |15,00                |15
12.3             |12,30                |12,3

What I am looking for is that it be rounded to 2 decimal places, if and only if it has 2 decimal places or more, I know that there is the possibility of passing the information a bit more formatted from the back-end, or doing it with force JavaScript, but I imagine that a DataTables has to have a solution for this, and I am not managing to locate it in its documentation.

I hope that someone has run into the same problem and can give me a hand, thank you very much!

EDIT: For the moment, I managed to solve it in the following way

{
    data: 'ejemplo',
    render: function (data, type, row, meta) { return (data + "").replace('.', ',') }
}

But as I said a bit above, I assume that the DataTables API has to have a better solution (which also helps with the . for the thousands

    
asked by Juan Salvador Portugal 02.07.2018 в 15:18
source

0 answers