JbPivot - Format in figures

0

Good afternoon:

I have implemented the jbpivot library using the following:

$(document).ready(function(){
          $("#pivot1").jbPivot({
             fields: {
               Clase_doc: { field: ''clase_doc'', sort: "asc", showAll:true},
               No_documento: { field: ''no_documento'', sort: "asc", no_documento: "No_documento", showAll:false, agregateType: "distinct"},
               Cuenta_gastos: { field: ''cuenta_gastos'', sort: "asc", showAll:true, agregateType: "distinct"},
               Importe: { field: ''importe'', sort: "asc", showAll:false, agregateType: "distinct"},
               Asignacion: { field: ''asignacion'', sort: "asc"},
               Id_Cliente: { field: ''id_cliente'', sort: "asc"},
             
               Division: { field: ''division'', sort: "asc"},
               Doc_pedido: { field: ''doc_pedido'', sort: "asc"},
               Id_Proyecto: { field: ''id_proyecto'', sort: "asc"},
               Proyecto: { field: ''proyecto'', sort: "asc"},
               Fecha: { field: ''fecha'', sort: "asc"},
               Fec_entrada: { field: ''fec_entrada'', sort: "asc"},
               Moneda: { field: ''moneda'', sort: "asc"},
               Elemento_pep: { field: ''elemento_pep'', sort: "asc"},
               Desc_elemento: { field: ''desc_elemento'', sort: "asc"},
               Sum: {  field: ''importe'', agregateType: "sum" , enableValue: true, format: "{0:c}" },
            },
            xfields: [ "Clase_doc", "No_documento","Id_Cliente", "Division" ], 
            yfields: [ "Cuenta_gastos" ],
            zfields: [ "Sum"],
            data: [ 
            
            
            {clase_doc:"ZF2", no_documento:"0090021423",cuenta_gastos:"212012", asignacion:"FA-00016020", id_cliente:"20052  - S.A.", division:"I.P.", Doc_pedido:"", id_proyecto:"0001",  proyecto:"AGUAS VERACRUZ", fecha:"15/08/14", fec_entrada:"15/08/2017", moneda:"MXN", elemento_pep:"", desc_elemento:"", importe:"1955789.27"},
{clase_doc:"ZF2", no_documento:"0090025424",cuenta_gastos:"401000", asignacion:"FA-00016021", id_cliente:"20033  -  T S.A DE C.V.", division:"I. P.", Doc_pedido:"", id_proyecto:"0001.12.002",  proyecto:"GTT PUEBLA", fecha:"15/08/17", fec_entrada:"15/08/2017", moneda:"MXN", elemento_pep:"002.1", desc_elemento:"LARGOS PUEBLA", importe:"158959816.25"},
           ]
          });
        });
<link href="http://www.jbPivot.org/css/jbpivot.min.css" rel="stylesheet"/>
<script src="http://www.jbPivot.org/js/vendor/jbpivot.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

But when doing the sum, the figures show them to me without separation of commas. Someone could help me? It shows: 55695626 and I need to show 55,695,626.56

I also require that the names of the columns (such as headings) be shown. and why, there are summations that appears in the text NaN?

I hope someone can help me.

Thanks !!

    
asked by ALONDRA PEREZ 05.09.2017 в 22:46
source

1 answer

0

According to the documentation you can format the value of your sum by:

formatter: function(val) {
        return separador(val);
        }

function separador(valor) {
    var nums = new Array();
    var simb = ",";
    valor = valor.toString();
    valor = valor.replace(/\D/g, "");
    nums = valor.split("");
    var long = nums.length - 1; 
    var patron = 3;
    var prox = 2;
    var res = "";
 
    while (long > prox) {
        nums.splice((long - prox),0,simb);
        prox += patron; 
    }
 
    for (var i = 0; i <= nums.length-1; i++) {
        res += nums[i];
    }
 
    return res;
}

var numero=separador(1234452);
alert("numero ya separado :"+numero);
    
answered by 05.09.2017 в 23:17