Datatable Data Format Problem

Asked

Viewed 765 times

1

Good morning

I’m having trouble formatting values in Datatable:

In the Limit, Open, Operated columns it returns values in the US pattern like:

38000.00

I want to leave in the Brazilian standard:

38.000,00

 $('.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'
                    ],
                   "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++) {

                                console.log(numero(json[i]['limite_usu']));
                                return_data.push({

                                  'razao_usu': json[i]['razao_usu'],
                                  'cnpj_usu' :  json[i]['cnpj_usu'],
                                  'limite_usu' :  'R$ '+ json[i]['limite_usu'],
                                  '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' }
                    ]   
                });

Thank you

2 answers

1

You can add the property columnDefs in the options, but first, remove the R$ of the columns.

For example, instead of 'limite_usu' : 'R$ '+ json[i]['limite_usu'],, use 'limite_usu' : json[i]['limite_usu'],.

,"columnDefs": [{
   "render": function(data){
      return parseFloat(data).toLocaleString('pt-br',{style: 'currency', currency: 'BRL'});
   },
   "targets": [2,3,4]
}]

The values in targets are the indexes of the columns, where 2 is the 3rd column, 3 to 4th and so on.

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.