Search code examples
javavaadinvaadin8vaadin-grid

How to fill table/grid manually


I am using Vaadin 8 and I want to make some sort of confusion matrix. I was wondering if I can fill the values of the table/grid manually according to the cell position, instead of data provider.

referenceTable.addColumn(reference -> String.valueOf(reference.getId())).setId(REFERENCE_ID).setCaption(REFERENCE_ID).setMinimumWidth(100).setMaximumWidth(200);
referenceTable.addColumn(reference -> String.valueOf(reference.getTitle())).setId(TITLE_COLUMN).setCaption(TITLE_COLUMN).setMinimumWidth(100).setMaximumWidth(500);

I don't have any specific model which I can use.

Something like this, I want enter image description here


Solution

  • Typically Grid in Vaadin is typed with POJO type bean and the API is optimized for that use case. However you can potentially use Grid with any valid type parameter. You can e.g. use List or HashMap<String,String> just to name few.

    In GitHub there is Vaadin 8 example of Grid using ArrayList, which makes possible to use index to access the data for the column. The full code is too extensive to be featured here. The example contains also demonstrator for style generator.