set data to Grid

Hi my previous experience was about Swing.
Are there any other ways to set data to Grid except setItems(object) either binded or not? For example to JTable you could have 2 dimension array or ArrayList. If there are can you point me to examples?

Thank you in advance

Hi,

You can use setItems that takes a Collection but also a dataprovider:
https://vaadin.com/docs/v14/flow/binding-data/tutorial-flow-data-provider.html

Hi and thanks for the answer.
Can you please give a sample of Collection code used with Grid?

My objective is to use Grid like grid.setItems(Record) where Record is a class with variable number of parameters each time.

Any suggestions?
Thank

Hi,

The grid component helps you to: (in short)

  • create a column that renders a data (A Java lamdba expression for example)
  • set a collection a data

Basically:

Grid<Record> grid = new Grid<>();
// build all the needed columns
grid.addColumn(record -> record.getYourData()); 
grid.setItems(records); //records is a list or collection of record

Record can contain anything but you need to know which column you will show.