Search code examples
javavaadinvaadin-grid

How to create excel like table using Vaadin Grid?


I would like to populate a Vaadin Grid that gets data from different SQL tables and represent them all in a single grid in a matrix-like structure.

excel like table

For example, the second row gets data from the Monitoring table, the third row gets data from the deployment table, and so on. Similarly, the Consultant column gets data from the consultant table, and Region 1,2 and 3 columns get data from different region tables.

Is there an efficient Vaadin-way to achieve this? Thank you.

So far I am able to populate my grid with a single DTO source.

grid.addColumn(RegionData::getRegion).setHeader("Region 1");
grid.addColumn(RegionData::getRegion).setHeader("Region 2");
grid.addColumn(RegionData::getRegion).setHeader("Region 3");

How can I add Areas and Consultant columns in the same grid?


Solution

  • TL;DR: you have to do it yourself.

    The Grid can only show you a row output for a row of input - so it's your job to join your data into this row.

    Join the tables in the DB, which is usually the most efficient; if you have to merge different sources, make sure to cache or batch to avoid the "n+1" problem.

    If you also have dynamic columns, you can store a row in a Map. SO has several examples (like Create "rotated" non-buffered grid (Vaadin) or Vaadin - adding columns to grid from map) to show you how.