Search in sources :

Example 21 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridWithTemplatePage method createGridInATemplateWithTemplatesInTheDetails.

private void createGridInATemplateWithTemplatesInTheDetails() {
    GridInATemplate gridInATemplate = new GridInATemplate();
    gridInATemplate.setId("injected-template-in-details");
    Grid<String> grid = gridInATemplate.getGrid();
    setCommonGridFeatures(grid, gridInATemplate.getId().get());
    grid.addColumn(value -> value);
    grid.setItemDetailsRenderer(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get())));
    add(new H3("Grid with templates in the details"), gridInATemplate);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Element(com.vaadin.flow.dom.Element) Div(com.vaadin.flow.component.html.Div) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) H3(com.vaadin.flow.component.html.H3)

Example 22 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class ItemClickListenerPage method createGridWithChangingKeysOfItemsAndFocusableHeader.

private void createGridWithChangingKeysOfItemsAndFocusableHeader() {
    Span message = new Span();
    message.setId("item-click-event-log");
    ListDataProvider<String> dataProvider = new ListDataProvider<>(Arrays.asList("a", "b", "c"));
    Grid<String> grid = new Grid<>();
    grid.setItems(dataProvider);
    grid.addColumn(x -> x).setHeader("Header");
    grid.addItemClickListener(ev -> message.setText("ItemClicked"));
    grid.setId(GRID_FILTER_FOCUSABLE_HEADER);
    Button filterButton = new Button("Filter");
    filterButton.setId("filterButton");
    Button clearFilterButton = new Button("Clear filter");
    clearFilterButton.setId("clearFilterButton");
    filterButton.addClickListener(event -> filterGrid(dataProvider, "b"));
    clearFilterButton.addClickListener(event -> filterGrid(dataProvider, null));
    TextField focusableHeader = new TextField();
    focusableHeader.setId("focusableHeader");
    grid.prependHeaderRow().getCells().get(0).setComponent(focusableHeader);
    add(grid, filterButton, clearFilterButton, message);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Button(com.vaadin.flow.component.button.Button) SerializableFunction(com.vaadin.flow.function.SerializableFunction) Arrays(java.util.Arrays) Grid(com.vaadin.flow.component.grid.Grid) Div(com.vaadin.flow.component.html.Div) TextField(com.vaadin.flow.component.textfield.TextField) StringUtils(org.apache.commons.lang3.StringUtils) Span(com.vaadin.flow.component.html.Span) Route(com.vaadin.flow.router.Route) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Button(com.vaadin.flow.component.button.Button) Grid(com.vaadin.flow.component.grid.Grid) TextField(com.vaadin.flow.component.textfield.TextField) Span(com.vaadin.flow.component.html.Span)

Example 23 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class JoinedHeadersPage method createGrid2.

private static Grid<String> createGrid2() {
    Grid<String> grid = new Grid<>();
    grid.setId("grid2");
    addColumns(grid);
    grid.appendHeaderRow();
    HeaderRow header = grid.prependHeaderRow();
    header.join(header.getCells()).setText("Title");
    grid.setItems("1", "2", "3");
    return grid;
}
Also used : HeaderRow(com.vaadin.flow.component.grid.HeaderRow) Grid(com.vaadin.flow.component.grid.Grid)

Example 24 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridTestPage method createGridWithComponentRenderers.

private void createGridWithComponentRenderers() {
    Grid<Item> grid = new Grid<>();
    grid.setSelectionMode(Grid.SelectionMode.MULTI);
    AtomicBoolean usingFirstList = new AtomicBoolean(true);
    List<Item> firstList = generateItems(20, 0);
    List<Item> secondList = generateItems(10, 20);
    grid.setItems(firstList);
    grid.addColumn(new ComponentRenderer<>(item -> {
        Label label = new Label(item.getName());
        label.setId("grid-with-component-renderers-item-name-" + item.getNumber());
        return label;
    })).setKey("name").setHeader("Name");
    grid.addColumn(new ComponentRenderer<>(item -> {
        Label label = new Label(String.valueOf(item.getNumber()));
        label.setId("grid-with-component-renderers-item-number-" + item.getNumber());
        return label;
    })).setKey("number").setHeader("Number");
    grid.addColumn(new ComponentRenderer<>(item -> {
        NativeButton remove = new NativeButton("Remove", evt -> {
            if (usingFirstList.get()) {
                firstList.remove(item);
            } else {
                secondList.remove(item);
            }
            grid.getDataProvider().refreshAll();
        });
        remove.setId("grid-with-component-renderers-remove-" + item.getNumber());
        return remove;
    })).setKey("remove");
    grid.addColumn(TemplateRenderer.<Item>of("hidden")).setHeader("hidden").setKey("hidden").setVisible(false);
    grid.setId("grid-with-component-renderers");
    grid.setWidth("500px");
    grid.setHeight("500px");
    NativeButton changeList = new NativeButton("Change list", evt -> {
        if (usingFirstList.get()) {
            grid.setItems(secondList);
        } else {
            grid.setItems(firstList);
        }
        usingFirstList.set(!usingFirstList.get());
    });
    changeList.setId("grid-with-component-renderers-change-list");
    NativeButton toggleColumnOrdering = new NativeButton("Toggle column ordering", evt -> {
        grid.setColumnReorderingAllowed(!grid.isColumnReorderingAllowed());
    });
    toggleColumnOrdering.setId("toggle-column-ordering");
    NativeButton setReorderListener = new NativeButton("Set reorder listener", evt -> {
        grid.addColumnReorderListener(e -> {
            if (e.isFromClient()) {
                List<Column<Item>> columnList = e.getColumns().stream().collect(Collectors.toList());
                // Reorder columns in the list
                Collections.swap(columnList, 1, 2);
                grid.setColumnOrder(columnList);
            }
        });
    });
    setReorderListener.setId("set-reorder-listener");
    Span currentColumnOrdering = new Span();
    currentColumnOrdering.setId("current-column-ordering");
    grid.addColumnReorderListener(e -> currentColumnOrdering.setText(e.getColumns().stream().map(Column::getKey).collect(Collectors.joining(", "))));
    add(grid, changeList, toggleColumnOrdering, setReorderListener, currentColumnOrdering);
}
Also used : 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) Span(com.vaadin.flow.component.html.Span) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Column(com.vaadin.flow.component.grid.Grid.Column)

Example 25 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridTestPage method createGridWithRemovableColumns.

private void createGridWithRemovableColumns() {
    Grid<Item> grid = new Grid<>();
    grid.setItems(generateItems(20, 0));
    Column<Item> removedColumn = grid.addColumn(Item::getName);
    Column<Item> nameColumn = grid.addColumn(Item::getName);
    grid.addColumn(Item::getNumber);
    grid.removeColumn(removedColumn);
    NativeButton removeNameColumn = new NativeButton("Remove name column", evt -> {
        grid.removeColumn(nameColumn);
        // forces refresh of the data
        grid.getDataCommunicator().reset();
    });
    grid.setId("grid-with-removable-columns");
    grid.setWidth("500px");
    grid.setHeight("500px");
    removeNameColumn.setId("remove-name-column-button");
    add(grid);
    add(removeNameColumn);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid)

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