Filling table horizontally instead of vertically

Kind of a weird question, but we like Tables in our application ( we use a handy “export” tool to allows users to export tp Excel ), so we wanted to do a 4 row table with an undefined number of columns ( could be 2 columns, could be 30 columns ). Basically, instead of loading the table row by row, we would load the table column by column. We tend to do something like this:

new TempConsumptionContainer( service.getConsumptionScans(
loginUser, form.getFacilityId(), searchMinutes)));
table.setVisibleColumns( VISIBLE_COLUMNS );

So my question is: has anyone found a good way to do this type of loading horizontally?

One obvious way is to rebuild the table every time based on the data, creating each row one at a time using the method defined in the documentation
. Just making sure there is not another way.

Yes, there is a usecase for this. In our case, the attached picture shows what we want. Basically, one column refers to one set of data.

The only reason I am trying to use tables is because the customer really likes to export to excel. If it weren’t for that, I would use a bunch of VerticalLayout panels inside a HorizontalLayout panel. So far I don’t see how to export a panel to Excel, but I do have a way to export tables to Excel.


If you want to use Table (or Grid), yes, the only way to do that would be to shape your data in a way that you define properties for each new data item (=column). However, have you considered
Vaadin Spreadsheet
? It’ll give you Excel integration on a whole new level and you can shape your data however you want.


First of all, I like you you phrased my requirement better than I phrased it: “If you want to use Table (or Grid), yes, the only way to do that would be to shape your data in a way that you define properties for each new data item (=column)”. I would add to that this would mean I would programatically shape my table to fit my data ( one column one time, 5 columns next time, and so on, filling each column one row at a time from the data bean for that column ). So I would have to fill row one with all “bucket numbers” from my data bean ( or actually count it manually ), fill row two with all the “dates” from my various buckets, and so on, formatting data correctly for each row ( or adding editable components where the row needs it ).

An interesting idea, but normally we don’t have Excel sheets on the server. Actually, we normally don’t want them. The “export” is purely for the users, and basically let’s them play with data locally. The table is always filled from the DB, NEVER from an excel sheet.

That said, out of curiosity, how would you define data per column? Or maybe a better way of putting it would be: how do you bind a data bean to a column in Excel? It sounds like you know of a way, but all the documentation I have seen talks about filling cells one by one, which is not much better then programatically shapping my table to fit my data ( see above ).

In case anyone was wondering, what I ended up doing was the following:

  1. Clear the extra column (new data set has less then prior filling of table ), or add missing columns ( current data set has more then prior filling of table )
  2. Make an “ArrayList” object for each row in the table. So each element in this list represents a column. In my case, the first element is always the “caption” for the line. After that, I add elements of the appriate type ( DateField, TextField, etc ). Call this “rowArrayList” below.
  3. In my case, since really a distinct data bean is a column, not a row, I have to stored the bean in a hash table based on the column number.
  4. Clear the table with: table.removeAllItems();
  5. Create row array as follows: Object row = rowArrayList.toArray();
  6. Assign name to row ( nameOfRow below )
  7. Add to table with: table.addItem( row, nameOfRow );

Kind of complex, in my case, but it works rather well.