It’s possible to show a list of string in a GridPro (and make then editable?) in my bean I have a List, show I need to show that list in a Grid with editable row…
How can I does this?
tks
It’s possible to show a list of string in a GridPro (and make then editable?) in my bean I have a List, show I need to show that list in a Grid with editable row…
How can I does this?
tks
You can create a grid of Integers for the elements’ indexes and use the index to read/update the data directly on the list.
package org.test;
import com.vaadin.flow.component.gridpro.GridPro;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* The main view contains a button and a click listener.
*/
@Route
@PWA(name = "My Application", shortName = "My Application")
public class MainView extends VerticalLayout {
public MainView() {
Bean bean = new Bean();
bean.data.addAll(createItems());
GridPro<Integer> gridPro = new GridPro<>();
gridPro.setItems(IntStream.range(0,bean.data.size()).boxed().collect(Collectors.toList()));
gridPro.addEditColumn(bean.data::get).text(bean.data::set);
add(gridPro);
}
private List<String> createItems() {
return Arrays.asList("a", "b", "c");
}
public static class Bean {
private List<String> data = new ArrayList<>();
}
}