What simple thing am I missing here? Is there a setKey method in the Grid

What simple thing am I missing here?

Is there a setKey method in the Grid.Column API in Vaadin 8.6.4? I can’t find it. A typical column definition for my Grid<Map<String, Object>> is:

Column<Map<String, Object>, ?> activityColumn
= addColumn(map -> (String)map.get("activity"))
.setCaption("Activity")
.setWidth(150d)
.setSortProperty("activity")
.setId("activity");

The example shows adding a .setKey(“…”) to the column definition. How is that done?

Oh, sorry for the confusion, the setKey() method is for Vaadin 10+. In Vaadin 8, it’s setId().

I will update the description to make it more clear

Thanks very much for looking into this. The framework version 2.0.0 uses flow imports, and getKey() in FileBuilder. I tried to adapt your source but got stuck with InputStreamFactory in Exporter that doesn’t have a Vaadin 8 equivalent?

In vaadin 8, it’s a bit different, there is FileDownloader, which takes an StreamResource. See an example code below.

Button downloadAsExcel = new Button("Download As Excel");

StreamResource excelStreamResource = new StreamResource((StreamResource.StreamSource) () -> Exporter.exportAsExcel(grid), "my-excel.xls");
FileDownloader excelFileDownloader = new FileDownloader(excelStreamResource);
        excelFileDownloader.extend(downloadAsExcel);

There were a few hurdles to getting this working, all due to my configuration. You’ve made assumptions about the grid, some of which were untrue in my case:

  1. I don’t use Beans to back grids, instead opting for the much more flexible Map<String, Object>. So the BeanPropertySet concept didn’t work for me.

  2. I use multiple headers in the grids in question which have some data derived from the captions, some not.

After the required grid-specific hacks, it works perfectly. Thanks very much for your hard work on this. I could not have solved it without your code paving the way.

Thank you so much for the very valuable feedback, really glad to hear that it’s somehow helpful. The idea of this addon is that first make a very simple version, and roll it out quickly to get some feedback, then add more features along the way.