Search in sources :

Example 26 with Grid

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) List(java.util.List) Column(com.vaadin.flow.component.grid.Grid.Column) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) HasComponents(com.vaadin.flow.component.HasComponents) Collections(java.util.Collections) Span(com.vaadin.flow.component.html.Span) NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid) Label(com.vaadin.flow.component.html.Label) HasComponents(com.vaadin.flow.component.HasComponents)

Example 27 with Grid

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);
}
Also used : Grid(com.vaadin.flow.component.grid.Grid) H2(com.vaadin.flow.component.html.H2)

Example 28 with 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);
}
Also used : Grid(com.vaadin.flow.component.grid.Grid) H2(com.vaadin.flow.component.html.H2)

Example 29 with 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");
}
Also used : IntStream(java.util.stream.IntStream) Person(com.vaadin.flow.data.bean.Person) Grid(com.vaadin.flow.component.grid.Grid) Anchor(com.vaadin.flow.component.html.Anchor) GridInATemplate(com.vaadin.flow.component.grid.it.GridInATemplate) H1(com.vaadin.flow.component.html.H1) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Hr(com.vaadin.flow.component.html.Hr) Route(com.vaadin.flow.router.Route) NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid) H1(com.vaadin.flow.component.html.H1) Hr(com.vaadin.flow.component.html.Hr) Person(com.vaadin.flow.data.bean.Person)

Example 30 with Grid

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-");
}
Also used : Div(com.vaadin.flow.component.html.Div) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) Label(com.vaadin.flow.component.html.Label)

Aggregations

Grid (com.vaadin.flow.component.grid.Grid)73 Route (com.vaadin.flow.router.Route)41 Div (com.vaadin.flow.component.html.Div)38 List (java.util.List)26 NativeButton (com.vaadin.flow.component.html.NativeButton)22 Person (com.vaadin.flow.data.bean.Person)22 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)21 H2 (com.vaadin.flow.component.html.H2)17 Collections (java.util.Collections)16 Button (com.vaadin.flow.component.button.Button)15 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)14 ArrayList (java.util.ArrayList)13 Collectors (java.util.stream.Collectors)13 Component (com.vaadin.flow.component.Component)12 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)12 Column (com.vaadin.flow.component.grid.Grid.Column)12 Label (com.vaadin.flow.component.html.Label)12 Span (com.vaadin.flow.component.html.Span)11 TextField (com.vaadin.flow.component.textfield.TextField)10 DenseGrid (io.imunity.furms.ui.components.DenseGrid)10