Download component in grid

Good day all, I would like to know if someone can help me establish the following:
I have a grid with a form.
Every time I save the form, it creates a new row with the values from the form.
What I want now, is a download button on every row, to download the content of the selected row and put it in a text file.
So in the end, I’ll be able to download a .txt file with contents of the selected row.

I’m using Vaadin 10

Please help.

At least in a simple case, it’s doable with something like follows:

        // Grid of Strings for simplicity
        Grid<String> grid = new Grid<>();
        grid.setItems("foo", "bar");
        grid.addColumn(s -> s).setHeader("Plain String value");
        grid.addComponentColumn(someStringItem -> {
            Button button = new Button("Download " + someStringItem + "-text.txt");
            Anchor anchor = new Anchor(new StreamResource(someStringItem + "-text.txt", new InputStreamFactory() {
                public InputStream createInputStream() {
                    return new ByteArrayInputStream(someStringItem.getBytes());
            }), "");
            anchor.getElement().setAttribute("download", true);
            return anchor;

Thank you very much Olli, it worked!!!