Skip to content

Exporting a grid with joined columns in csv format / Excel doubles Custom Header #190

@RalfNiehausIVE

Description

@RalfNiehausIVE

Describe the bug

When exporting a grid with joined columns the result csv output shows only the joined value.

If I define a custom header to merge the two headers, the excel export doubles the custom header.

It is not possible to define only a custom header for the csv export. So I have to decide which output is broken csv or excel.

Expected behavior

No response

Minimal reproducible example

CSV shows only joined Header

@Route("grid-exporter-test")
@PermitAll
public class GridExporterTest extends VerticalLayout {

    record Person(String firstname, String lastname) {}

    public GridExporterTest() {
        Grid<Person> grid = new Grid<>();
        var colFirstname = grid.addColumn(Person::firstname).setHeader("Firstname");
        var colLastname = grid.addColumn(Person::lastname).setHeader("Lastname");
        grid.setItems(new Person("Alice", "Bob"), new Person("Jane", "Doe"));

        HeaderRow headerRow = grid.prependHeaderRow();
        Div cellTotal = new Div("Joined cells");
        cellTotal.getStyle().set("text-align", "center");
        headerRow.join(colFirstname, colLastname).setComponent(cellTotal);

        GridExporter gridExporter = GridExporter.createFor(grid);
        gridExporter.setAutoAttachExportButtons(true);
        gridExporter.setTitle("MontageFortschritt");

        add(grid);
    }
}

Excel doubles Custom Header

@Route("grid-exporter-test")
@PermitAll
public class GridExporterTest extends VerticalLayout
{

    record Person(String firstname, String lastname) {}

    public GridExporterTest()
    {
        Grid<Person> grid = new Grid<>();
        var colFirstname = grid.addColumn(Person::firstname).setHeader("Firstname");
        var colLastname = grid.addColumn(Person::lastname).setHeader("Lastname");
        grid.setItems(new Person("Alice", "Bob"), new Person("Jane", "Doe"));

        HeaderRow headerRow = grid.prependHeaderRow();
        Div cellTotal = new Div("Joined cells");
        cellTotal.getStyle().set("text-align", "center");
        headerRow.join(colFirstname, colLastname).setComponent(cellTotal);

        GridExporter gridExporter = GridExporter.createFor(grid);
        gridExporter.setAutoAttachExportButtons(true);
        gridExporter.setTitle("MontageFortschritt");

        gridExporter.setCustomHeader(colFirstname, "join_firstName");
        gridExporter.setCustomHeader(colLastname, "join_lastName");

        add(grid);
    }

Add-on Version

2.5.2

Vaadin Version

24.5.14

Additional information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions