0
I am making a report, using grails and the export plugin and I have a problem. I have fields that depending on the situation can come null, I do a search with criteria in a certain class, there I have data among other things of vehicles and equipment, when the data is of a vehicle I have the plate, more when it is an equipment that field is null, because the equipment does not have plate, however it has the equipment Cod..
When I export the report I want the field "plate" to be empty when it is an equipment, same thing for the field "equipment Cod" when it is vehicle, but in the report appears the value of the next non-zero field.
Another thing is that I am not able to format the date field, to show only the time, since the value of the variable is date and time.
follows an example snippet of the controller code, with some attempts of mine to format that are commented because they did not work:
if (params?.f && params.f != "html") {
response.contentType = grailsApplication.config.grails.mime.types[params.f]
response.setHeader("Content-disposition", "attachment; filename=exemplo.${params.extension}")
// def placa = { _, value ->
// return value?.maquina.placa + " "
// }
// def date = {_,value -> value?.format('hh:MM:ss')}
List fields = ["dateCreated","dateCreated","maquina.placa", "maquina.codigo" ]
Map labels = [ "dateCreated": "Data","dateCreated": "Hora",
"maquina.placa": "Placa", "maquina.codigo": "Cod Equipamento" ]
// Map formatters = [ ]
/* def data = { _, value ->
return _?.maquina.placa + "---- "
Map formatters = [
maquina.placa: data
dateCreated : dateCreated.format('dd/MM/yyyy')
dateCreated : dateCreated.format('HH:mm:ss')
] */
exportService.export(params.f,
response.outputStream,
exemploService.list(params, false),
fields,
labels, [:], [:])
return
}```
[1]: http://plugins.grails.org/plugin/grails/export ```