FlowingCode / GridExporterAddon

Apache License 2.0
10 stars 9 forks source link

Inconsistent Styling of Footer Cell in Certain Cases #105

Closed brunoagretti closed 5 months ago

brunoagretti commented 6 months ago

When using a custom NumberColumnFormatProvider, an inconsistency in styling occurs for footer cells when their styles match those of the rows. In those cases, the footer cell's style is erroneously set as if it were a data cell.

This issue is reproducible with the following simple grid and exporter example:

Grid<String> myGrid = new Grid<>();                                                                                    
Column<String> itemColumn = myGrid.addColumn( str -> str).setHeader("Item");                                           
Column<String> upperColumn = myGrid.addColumn( str -> String.valueOf(Math.random() * 100)).setHeader("Number");        
itemColumn.setFooter("Unformatted footer");                                                                            
upperColumn.setFooter("50.00");                                                                                        

myGrid.setItems(new ArrayList<>(List.of("Item 1", "Item 2", "Item 3")));                                               
add(myGrid);                                                                                                           

GridExporter<String> exporter = GridExporter.createFor(myGrid);                                                        
exporter.setNumberColumnFormatProvider(upperColumn, new DecimalFormat("#,##0.000"), item -> {                          
    if (item == null)                                                                                                  
    {                                                                                                                  
        return "$ #,##0.000";                                                                                            
    }                                                                                                                  
    return "#,##0.000";                                                                                                
});                                                                                                                    

When executing this example and exporting the grid to xlsx format, the output matches the expected styling: image

However, after changing the format of the column for null items (the format for the footer) to match the formats of other items, we encounter an unexpected change in the footer's background color. Instead of using the footer's expected background color, it adopts the background color of the data cells:

exporter.setNumberColumnFormatProvider(upperColumn, new DecimalFormat("#,##0.000"), item -> {
    if (item == null) {
        // Changed to match the other rows' formats
        return "#,##0.000";
    }
    return "#,##0.000";
});

This inconsistency in footer cell styling is visually shown below: image

mlopezFC commented 6 months ago

I investigated the issue. I think that the problem is already reproducible in the custom templates demo. As you can see, the footer is using the conditional formatting that is only defined for the regular rows, not for the footer: image But I still cannot find where the issue is, will continue investigating.