Vaadin 8 Grid: Using PropertySet

I’m migrating the second of ~60 Grids from SQLContainer-backed Grids in Vaadin 7 to Vaadin 8. So far, each grid has been a multi-day process full of technical challenges but mostly tedious re-working because of the need to create a dedicated bean for each grid, integrate it with an sql query, and Grid columns.

Before going any further, I’d like to experiment with PropertySet but don’t know how to use it. Is there any documentation or an example available?

Ideally Grid would use a List<HashMap<String, Object>> as a backing, because this can be loaded easily from a database result set and will automatically change its structure depending on the database query - more columns, more entries in the map. But then Grid has no way to reference the columns (= Hashmap keys). I wonder if I could build something using PropertySet?

Hi Steve, did you resolve this problem? I’m facing the same … data beeing fetched from Elasticsearch … as List<HashMap<String, Object>> … how to display such data using Vaddin 8 Grid?

It turned out that it was not necessary to use PropertySet.

Instead a database query returns a List<Map<String, Object>> (the Map is a HashMap) and that query is run in the DataProvider.fromCallbacks() method which returns a DataProvider<Map<String, Object>, Void> object. That is used to back a grid:

setDataProvider(dataProvider);

Then each column is defined and configured by reference to the HashMap with each object cast to the appropriate type. Here is an example of one grid column being defined:

Column<Map<String, Object>, ?> timeColumn
= addColumn(map -> (Timestamp)map.get(DataAccess.TIME_EVENT))
.setRenderer(gridHelper.new SpecialDateRenderer())
.setCaption("Event Created")
.setWidth(timeColumnWidth)
.setSortProperty(DataAccess.TIME_EVENT)
.setStyleGenerator(map -> gridHelper.getTodayColour((Timestamp)map.get(DataAccess.TIME_EVENT)));

Tell me if any of this is unclear and I will try to fill the gaps.

Thanks a lot! One more question. Our former solution based on Vaadin 7 Grid used multicolumn sorting … guess you use it as well. Data is sorted by backend system but we have to maintain visual infomation about sorting in column headers. Visualy it displays as small rectangles in column header. Now when I set default sort order with code as below, it doesnt show up on Grid. I can define GridSortOrder for one or two columns with no luck. Can’t see anything on screen (in column headers). Any idea how to accomplish this properly?

List<GridSortOrder<Map>> orders=new ArrayList();
orders.add(new GridSortOrder<>(colName,SortDirection.DESCENDING));
grid.setSortOrder(orders);

You’re right. Vaadin 8.0.6 Grids are not showing a visual indication of programmatic sort orders. Manually set sort orders - single or multicolumn sorting - are shown with the expected triangle and sort order number.

Checking GitHub, this has been identified as a bug, but I don’t see any progress with it.

https://github.com/vaadin/framework/issues/8316

Hmm, you are right. Its significant issue, for us probably showstoper for migrating to Vaadin 8 Grid for now. Homefully someone fix this. We are running on Vaadin 8.1beta1 …

Fixed in 8.1.0.beta3 and later, and in 8.0.7.