2

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

Anna Koskinen
  • 1,362
  • 3
  • 22
user1631306
  • 4,350
  • 8
  • 39
  • 74
  • 3
    Check this Grid with HashMap instead of POJO example, it is for newer Vaadin version, but Grid API is almost the same in Vaadin 8: https://cookbook.vaadin.com/grid-with-map – Tatu Lund Aug 07 '21 at 13:25
  • 1
    There is Vaadin 8 example of Grid using List as its type also here, which makes possible to use index to access the data for the column: https://github.com/tatulund/gridflip – Tatu Lund Aug 07 '21 at 13:28
  • That works. Can you please post it as answer. I will accept it. Thanks – user1631306 Aug 09 '21 at 16:25
  • Also, how can I implement StyleGenerator for each of the cell. I am using StyleGenerator, but it complains about not applicable for list – user1631306 Aug 09 '21 at 17:55
  • 1
    I added StyleGenerator to github.com/tatulund/gridflip and there seems not to be an issue about that. – Tatu Lund Aug 10 '21 at 06:49
  • I was using wrong iterator, instead of "index". Works thanks – user1631306 Aug 10 '21 at 18:42

1 Answers1

2

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.

Tatu Lund
  • 9,949
  • 1
  • 12
  • 26