SearchBuilder.getDetails()
SearchBuilder.getDetails()

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
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
https://live.datatables.net/upgrade/10420/
https://live.datatables.net/makubiyo/1/
Gives me an Ajax error trying to load
https://live.datatables.net/post_reg_leg/None
.Allan
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 '.'
Sorry, I'll try to explain myself better.
I have two endpoints.
/post_reg_leg for pagination, search, and searchbuilder. In this endpoint, amounts travel with a decimal separator, e.g., 1000.00.
/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.
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
no se si es correcto
son tres monitores
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 :
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
I built this test case:
https://live.datatables.net/qapabago/1/edit
And
searchBuilder.getDetails()
gets the correct number with the decimal point. Perform a search of the Salary column and you will see the output is like this with after clicking the Get Details button:Use the browser's network inspector tool to view the JSON response. Please post an example row, for example the row with value1 == 1000.00. Want to see if the original data contains the decimal point or if it is added during rendering.
Kevin
Are you looking at the browser's network inspector to see the parameters sent to the server?
I updated the test case to simulate using your function:
https://live.datatables.net/waqagina/1/edit
It errors due to the ajax url but the screenshot shows it sends the entered value of
1000.00
.We will need to see the issue to help debug. Please provide a running test case or update my test case to show the issue.
Kevin
Buenos dias ,
he probado en el Live.datatables y no se produce el error. siempre que en el campo del valor incluya el importe con separador '.' Ej: 300.00 , pero no es el caso. El valor debe ser introducido asi: 300,00
por este motivo he incluido en la estructura de idioma "thousands": '.', "decimal": ',' ademas de informar en columns render:DataTable.render.number('.',',',2,''). bajo esta configuracion searchBuilder busca y encuentra datos.
Cuando pulso el boton Search en el menu searchBuilder se produce la busqueda y devuelve valores. Los pasos que realiza son:
se realiza la busqueda me devuelve informacion.
pero cuando vuelve a realizar en getDetails this.o tiene el valor original es decir '300,00' y ejecuta esta parte del codigo
Pego pantalla del debug en el momento que se produce. La cuestion es que this.s.value contiene '30000' que es lo que devuelve la sigueinte vez que se llama getDetails().
Esto es lo que he podido averiguar , no tengo la certeza que ese sea el error y posiblemente tenga alguna carencia de parametrizacion.
muchas gracias por vuestro tiempo
Please try updating my test case to show the issue. Update the
salary
values of thedata
variable to numbers that reflect your source data format. Add thelanguage
and the number renderer to thesalary
column. Are you able to recreate the error?Post a link to the updated test case so we can see exactly what you have.
Kevin
https://live.datatables.net/kikiruca/4/edit
pero no se comporta de la misma manera . Searchbuilder acepta importes con ',' de separador de decimales , pero no encuentra nada , cuando deberia o al menos a mi si me encuentra informacion sin hacer transformaciones ya que searchbuilder hace el cambio al identificar el dato como float
en este punto searchbuilder me cambia el signo y pone '.' al importe por eso encuentra informacion
if (this.s.type && this.s.type.includes("num") && this.s.dt.page.info().serverSide)
for (i = 0; i < this.s.value.length; i++)
this.s.value[i] = this.s.value[i].replace(/[^0-9.-]/g, "");
return {
condition: this.s.condition,
data: this.s.data,
origData: this.s.origData,
type: this.s.type,
value: this.s.value.map(function(t) {
return null != t ? t.toString() : t
})
pero vuelve a ejecutarse y transforma el importe sin signo por que cuando vuelve a ejecutar esta parte this.s.value[i] tiene '1000,00' y al hacer el replace le elimina la ',' y deja 100000
desconozco por que vuelve a ejecutarse
buenos dias,
ademas de lo indicado anteriormente , algo no funciona correctaemnte ya que si hago esto que abajo indico el importe cambia:
1 .- selecciono un campo de importe y añado condicion Ej: igual
2.- tecleo 1000,00
3.- pulso el boton buscar
3.1 la primera vez que pulso buscar funciona correctamente
3.2 si vuelvo a pulsar buscar ya no funciona , por que internamente no es el mismo importe .
4 .- ademas si pulso añadir condicion y despues pulso borrar esa misma condicion , el importe 1000,00 cambia 1000.00
https://live.datatables.net/kikiruca/4/edit