SearchBuilder.getDetails()

SearchBuilder.getDetails()

PabloCamaraPabloCamara Posts: 25Questions: 4Answers: 0

Good afternoon,

I apologize for the translator's errors.

First, I can't reproduce the question because I'm in a highly secure environment.I'll try to explain my question with code fragments.I currently have an application that uses ServerSide for pagination, and everything works correctly.I've implemented a function to export the data to Excel. For the export, I get the filter applied in SearchBuilder, the visible columns, and the column names. Here's the code fragment for this:

WebBrowser net information:

{columnas_visibles: [true, true, true, true, true, true],…}
columnas: ["RUT_CLIENTE", "NUMERO_DI", "FECHA_ACEPTACION", "MONTO_DI", "MONTO_DI_DISPONIBLE",…]
columnas_visibles: [true, true, true, true, true, true]
filtre: {,…}
criteria: [{condition: "=", data: "Monto de DI USD", origData: "MONTO_DI", type: "num", value: **["100000"]}]**
0: {condition: "=", data: "Monto de DI USD", origData: "MONTO_DI", type: "num", value: ["100000"]}
logic: "AND"
type: "excel"

The problem is with obtaining the SearchBuilder criterion; when obtaining it, it removes the decimal point.

The definition of the columns indicates that they are numeric fields.

        columns: [
                { data: 'NUMERO_OPERACION'                 , title:'Nº Operación'          ,type:'string', className: "text-center"   },        
                { data: 'TIPO_MOVIMIENTO'                  , title:'Tipo de Movimiento'    ,type:'string', className: "text-center"   },
                { data: 'CODIGO_PLANILLA'                  , title:'Código de Planilla'    ,type:'string', className: "text-center"   },
                { data: 'PAIS_OPERACION'                   , title:'País de Operación'     ,type:'string', className: "text-left"   },
                { data: 'MONTO_OPERACION'                  , title:'Monto Operación'       ,type:'num', render:DataTable.render.number('.',',',2,''),className: "text-right"},
                { data: 'MONTO_OPERACION_USD'              , title:'Monto Operación USD'   ,type:'num', render:DataTable.render.number('.',',',2,''),className: "text-right"},
                { data: 'TIPO_CAMBIO'                      , title:'Tipo de Cambio'        ,type:'num', render:DataTable.render.number('.',',',2,''),className: "text-right"},
                { data: 'OBSERVACIONES'                    , title:'Observaciones'         ,type:'string', className: "text-left"   },
        ],

But when it reaches the server in the searchBuilder.getDetails() export function, it removes the decimal point from numeric fields.

This is the part of the call to export_excel.

arr_filtro: [[{'logic': 'AND', 'origData': 'MONTO_OPERACION', 'condition': '<', 'value1': '100000', 'value2': None, 'tipo': 'html-num-fmt'}]]
                           { extend: 'excelHtml5', 
                                    className: 'btn btn btn-light btn-outline-dark btn-sm-menu' ,
                                    text: 'Excel' , 
                                    title:'Reporte Códigos de comercio',
                                    exportOptions: { columns: ':visible' , orthogonal: 'export',stripHtml: false, decodeEntities: false},
                                    action: function ( e, dt , node , config ) {
                                        table.button(3).processing(true);
                                        exportarAlServidor('excel');
                                        table.button(3).processing(false);
                                        window.location.href = window.location.protocol +'//'+ window.location.host + window.location.pathname;
                                    },
                                    async: 50,
                                    autoFilter: true,
                                    excelStyles:{
                                        template:'gray_medium'
                                    },

                            }
    function exportarAlServidor(tipo) {
        var table               = $('#table_b').DataTable();
        var filtro              = table.searchBuilder.getDetails();
        var columnas_visibles   = table.columns().visible().toArray();
        var settings            = table.settings()[0];
        var aoColumns           = settings.aoColumns;
        var columnas            = aoColumns.map( column => column.data);
        var exportData = {
            'columnas_visibles': columnas_visibles,
            'columnas': columnas,
            'filtre': filtro,
            'type': tipo
        };
        $.ajax({
            url:'/export_excel',
            type:'POST',
            async: false,
            contentType: 'application/json',
            dataType: "json",
            data: JSON.stringify(exportData),
        });
        // Requery the server with the new one-time export settings
        window.location.href = window.location.protocol +'//'+ window.location.host + window.location.pathname;             
        table.ajax.reload();
    }   

Can you help me figure out what I'm doing wrong?

I tried changing the type value to 'num-fmt, html-num-fmt'

but nothing worked.

Thank you very much for your help.

Replies

  • allanallan Posts: 65,082Questions: 1Answers: 10,775 Site admin

    Are you able to use https://live.datatables.net , JSFiddle, StackBltiz or similar to create a test case showing the issue so I can look into it please?

    Thanks,
    Allan

  • PabloCamaraPabloCamara Posts: 25Questions: 4Answers: 0

  • PabloCamaraPabloCamara Posts: 25Questions: 4Answers: 0

  • allanallan Posts: 65,082Questions: 1Answers: 10,775 Site admin

    https://live.datatables.net/makubiyo/1/

    Gives me an Ajax error trying to load https://live.datatables.net/post_reg_leg/None.

    Allan

  • PabloCamaraPabloCamara Posts: 25Questions: 4Answers: 0
    edited 10:09AM

    This is the server access that will retrieve a page, and in this call, the amount is sent correctly. It's in the "Excel or CSV" export button where the amount doesn't have the decimal separator '.'

  • PabloCamaraPabloCamara Posts: 25Questions: 4Answers: 0

    Sorry, I'll try to explain myself better.

    I have two endpoints.

    1. /post_reg_leg for pagination, search, and searchbuilder. In this endpoint, amounts travel with a decimal separator, e.g., 1000.00.

    2. /export_excel: This endpoint sends information to the server (searchbuilder filter, visible columns). In this endpoint, when I get the filter with table.searchBuilder.getDetails(), the amount has no decimals, e.g., 100000. This is the problem or error I'm having.

  • allanallan Posts: 65,082Questions: 1Answers: 10,775 Site admin

    Can you write down the steps needed in your example to demonstrate the issue please? At the moment I get an alert with an Ajax error as soon as I load the page. I assume that's not meant to be there?

    Allan

  • PabloCamaraPabloCamara Posts: 25Questions: 4Answers: 0
    edited 2:12PM

    no se si es correcto

    son tres monitores

  • PabloCamaraPabloCamara Posts: 25Questions: 4Answers: 0

    Voy a intentar explicarme:

    esta es mi pantalla de searchbuilder

    el importe tecleado viaja al servidor de esta manera :
    /post_reg_leg --> arr_criterio: [[{'logic': 'AND', 'origData': 'MONTO_OPERACION', 'condition': '<', 'value1': '1000.00', 'value2': None, 'tipo': 'num'}]]

    value1 == 1000.00

    cuando pulso el boton de Excel se ejecuta el sigueinte codigo :

    function exportarAlServidor(tipo) {
        var table               = $('#table_b').DataTable();
        var filtro              = table.searchBuilder.getDetails();
        var columnas_visibles   = table.columns().visible().toArray();
        var settings            = table.settings()[0];
        var aoColumns           = settings.aoColumns;
        var columnas            = aoColumns.map( column => column.data);
        var exportData = {
            'columnas_visibles': columnas_visibles,
            'columnas': columnas,
            'filtre': filtro,
            'type': tipo
        };
        $.ajax({
            url:'/export_excel',
            type:'POST',
            async: false,
            contentType: 'application/json',
            dataType: "json",
            data: JSON.stringify(exportData),
        });
        // Requery the server with the new one-time export settings
        window.location.href = window.location.protocol +'//'+ window.location.host + window.location.pathname;             
        table.ajax.reload();
    }    
    

    envia la informacion al servidor perooooooo el campo value1 no tiene separador decimal

    'filtre': {'criteria': [{'condition': '<', 'data': 'Monto Operación', 'origData': 'MONTO_OPERACION', 'type': 'num', 'value': ['100000']}], 'logic': 'AND'}, 'type': 'excel'}

    ademas he observado que cuando pagino en serverSide el valor se encuentra en el campo "value1"

    y si obtengo el criterio en getDetails() el valor esta en "value"

    He intenentado grabar la operativa , pero no he sabido hacerlo . espero que esto aclara mas que confunda.

    gracias

Sign In or Register to comment.