Problem with formating values with comma(,) and point(.)

Problem with formating values with comma(,) and point(.)

mat_datatablemat_datatable Posts: 1Questions: 1Answers: 0
edited April 2019 in Free community support

Hey Guys,

I using DataTable and i having some problems to format values in the table, I am using AJAX Datable to return the value of table but some columns is returning values like "3800.00" or "9999.00"

What i need is format the numbers "3800.00" in "3.800,00";

I tried with toLocaleString('pt-br',{style: 'currency', currency: 'BRL'}); but don't work.

I tried with "decimal": ",", "thousands": ",", but didn't works...

There my code:

$('.table.aprovado').dataTable({
       "language" : {
            "decimal": ",",
            "thousands": ",",
            "sEmptyTable": "Nenhum registro encontrado",
            "sInfo": "Mostrando  _START_ até _END_ de _TOTAL_ Resultados",
            "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
            "sInfoFiltered": "(Filtrados de MAX registros)",
            "sInfoPostFix": "",
            "sInfoThousands": ".",
            "sLengthMenu": "_MENU_ resultados por página",
            "sLoadingRecords": "Carregando...",
            "sProcessing": "Processando...",
            "sZeroRecords": "Nenhum registro encontrado",
            "sSearch": "Pesquisar",
            "oPaginate": {
                "sNext": "Próximo",
                "sPrevious": "Anterior",
                "sFirst": "Primeiro",
                "sLast": "Último"
            },
            "oAria": {
                "sSortAscending": ": Ordenar colunas de forma ascendente",
                "sSortDescending": ": Ordenar colunas de forma descendente"
            }
        },
        dom: 'Bfrtip',  
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5'
        ],
        "aoColumnDefs": [
            { "sType": "numeric-comma", "aTargets": [2] }
        ],
       "order": [[ 6, 'desc' ]],
       "ajax": {
            "jQueryUI": true,
            "processing": true,
            "serverSide": true,
            "async": true,
            "url": base_url+'painel/Inscritos/buscaInscritosAprovado',
            "type": "POST",
            "dataSrc": function( json ){
                var return_data = new Array();

                for(var i=0; i<json.length; i++) {
                    return_data.push({

                      'razao_usu': json[i]['razao_usu'],
                      'cnpj_usu' :  json[i]['cnpj_usu'],
                      'limite_usu' : json[i]['limite_usu'].toLocaleString('pt-br',{style: 'currency', currency: 'BRL'}),
                      'aberto' : 'R$ '+json[i]['aberto'],
                      'operado' : 'R$ '+json[i]['operado'],
                      'email_usu' : json[i]['email_usu'],
                      'created_usu' : json[i]['created_usu']

                    })
                }
                return return_data;
            }
          },
        "aoColumns": [
            { "data": 'razao_usu' },
            { "data": 'cnpj_usu' },
            { "data": 'limite_usu' },
            { "data": 'aberto' },
            { "data": 'operado' },
            { "data": 'email_usu' },
            { "data": 'created_usu' }
            // { "data": 'juros' }
        ]   
    });

Answers

This discussion has been closed.