3

I have implemented an export functionality from a Vaadin 7 and Vaadin 8 Grid. Now we migrate to Vaadin 14 and I cannot find a way to get the header text.

I tried to work with the Renderer:

Column column = grid.getColumnByKey(columnKey);
Renderer renderer = column.getRenderer();
// renderer is a ColumnPathRenderer instance but does not provide information about the header.

So I try to get the information from the HeaderRow or better the HeaderCell:

Column column = grid.getColumnByKey(columnKey);
HeaderRow headerRow = grid.getHeaderRows().get(0);
HeaderCell cell = headerRow.getCell(column);
// cell contains a member 'headerRenderer', an instance of TemplateRenderer<SOURCE>, and this
// headerRenderer contains a member 'template' which contains my header text. But there is no
// API to get this information.

So, how can I get the header text from a Vaadin 14 HeaderCell?

bingele28
  • 61
  • 1
  • 5
  • 2
    I think you have two alternatives. Either to store the header text somewhere if you are using addColumn(..).setHeader(myText) or use alternative approach of generating the export. E.g. if you are using opencsv library, it uses propertynames of the Bean automatically for CSV header line, see example: https://cookbook.vaadin.com/grid-csv-export – Tatu Lund Jul 09 '21 at 07:43
  • I tried this with my own data model and implemented in a generic way, as my exporter need to handle various types of data in a Grid: ` ListDataProviderdataProvider = (ListDataProvider) m_stringGrid.getDataProvider(); Collection – bingele28 Jul 09 '21 at 08:46
  • Beside that, the export need to be written as XLS and PDF as well. But for CSV this is a good starter. – bingele28 Jul 09 '21 at 08:47

0 Answers0