use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class GridTestPage method createDetachableGrid.
private void createDetachableGrid() {
Div container1 = new Div(new Label("Container 1"));
container1.setId("detachable-grid-container-1");
Div container2 = new Div(new Label("Container 2"));
container2.setId("detachable-grid-container-2");
Grid<Item> grid = new Grid<>();
grid.setId("detachable-grid");
grid.setItems(generateItems(200, 0));
grid.addColumn(Item::getName);
container1.add(grid);
add(container1);
NativeButton detach = new NativeButton("Detach grid", e -> grid.getParent().ifPresent(parent -> ((HasComponents) parent).remove(grid)));
detach.setId("detachable-grid-detach");
NativeButton attach1 = new NativeButton("Attach grid to container 1", e -> container1.add(grid));
attach1.setId("detachable-grid-attach-1");
NativeButton attach2 = new NativeButton("Attach grid to container 2", e -> container2.add(grid));
attach2.setId("detachable-grid-attach-2");
NativeButton invisible = new NativeButton("Set grid invisble", e -> grid.setVisible(false));
invisible.setId("detachable-grid-invisible");
NativeButton visible = new NativeButton("Set grid visible", e -> grid.setVisible(true));
visible.setId("detachable-grid-visible");
add(container1, container2, detach, attach1, attach2, invisible, visible);
}
use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class GridMultiSelectionColumnPage method createInMemoryGrid.
private void createInMemoryGrid() {
Grid<String> grid = new Grid<>();
grid.setItems(IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString));
setUp(grid);
grid.setId(IN_MEMORY_GRID_ID);
add(new H2("In-memory grid"), grid);
}
use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class GridMultiSelectionColumnPage method createBasicGridFromSingleToMultiBeforeAttached.
private void createBasicGridFromSingleToMultiBeforeAttached() {
Grid<String> grid = new Grid<>();
grid.setItems(IntStream.range(0, ITEM_COUNT).mapToObj(Integer::toString));
setUp(grid);
grid.setId("in-testing-multi-selection-mode-grid");
add(new H2("in-testing-multi-selection-mode-grid"), grid);
grid.setSelectionMode(Grid.SelectionMode.SINGLE);
grid.setSelectionMode(Grid.SelectionMode.MULTI);
add(grid);
}
use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class ContextMenuGridPage method gridWithContextMenu.
private void gridWithContextMenu() {
final Grid<Person> grid = new Grid<>();
grid.addColumn(Person::getFirstName).setHeader("Name").setId("Name-Id");
grid.addColumn(Person::getAge).setHeader("Born").setId("Born-Id");
grid.setItems(IntStream.range(0, 77).mapToObj(i -> new Person("Person " + i, 1900 + i)));
GridContextMenu<Person> contextMenu = grid.addContextMenu();
addItems(contextMenu);
contextMenu.addComponentAtIndex(1, new Hr());
contextMenu.addGridContextMenuOpenedListener(event -> {
String name = event.getItem().map(Person::getFirstName).orElse(NO_TARGET_ITEM);
String columnId = event.getColumnId().orElse("No column");
message.setText("pre-open: name=" + name + ", colId=" + columnId);
});
NativeButton toggleOpenOnClick = new NativeButton("Toggle open on click", e -> contextMenu.setOpenOnClick(!contextMenu.isOpenOnClick()));
toggleOpenOnClick.setId("toggle-open-on-click");
NativeButton addSubMenu = new NativeButton("Add sub-menu", e -> {
GridMenuItem<Person> parent = contextMenu.addItem("parent");
GridSubMenu<Person> subMenu = parent.getSubMenu();
addItems(subMenu);
subMenu.addComponentAtIndex(1, new H1("bar"));
});
addSubMenu.setId("add-sub-menu");
NativeButton removeContextMenu = new NativeButton("Remove context menu", event -> contextMenu.setTarget(null));
removeContextMenu.setId("remove-context-menu");
add(grid, toggleOpenOnClick, addSubMenu, removeContextMenu);
grid.setId("grid-with-context-menu");
}
use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class GridItemRefreshPage method createComponentGrid.
private void createComponentGrid() {
Grid<Bean> grid = new Grid<>();
grid.setHeight("500px");
grid.addColumn(new ComponentRenderer<Label, Bean>(item -> new Label(item.getFirstField()))).setHeader("First Field");
grid.addColumn(new ComponentRenderer<Label, Bean>(item -> new Label(String.valueOf(item.getSecondField())))).setHeader("Second Field");
List<Bean> items = createItems(1000);
grid.setItems(items);
grid.setId("component-grid");
Div div = new Div();
div.setText("Component Grid");
add(div, grid);
addButtons(grid, items, "component-");
}
Aggregations