Search in sources :

Example 6 with Column

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

the class GridViewHeaderAndFooterRowsPage method createGridWithHeaderAndFooterRows.

private void createGridWithHeaderAndFooterRows() {
    Grid<Person> grid = new Grid<>();
    grid.setItems(createItems());
    Column<Person> nameColumn = grid.addColumn(Person::getFirstName).setHeader("Name").setComparator((p1, p2) -> p1.getFirstName().compareToIgnoreCase(p2.getFirstName()));
    Column<Person> ageColumn = grid.addColumn(Person::getAge, "age").setHeader("Age");
    Column<Person> streetColumn = grid.addColumn(person -> person.getAddress().getStreet()).setHeader("Street");
    Column<Person> postalCodeColumn = grid.addColumn(person -> person.getAddress().getPostalCode()).setHeader("Postal Code");
    HeaderRow topRow = grid.prependHeaderRow();
    HeaderCell informationCell = topRow.join(nameColumn, ageColumn);
    informationCell.setText("Basic Information");
    HeaderCell addressCell = topRow.join(streetColumn, postalCodeColumn);
    addressCell.setText("Address Information");
    grid.appendFooterRow().getCell(nameColumn).setText("Total: " + getItems().size() + " people");
    grid.setId("grid-with-header-and-footer-rows");
    addCard("Header and footer rows", "Adding header and footer rows", grid);
}
Also used : Column(com.vaadin.flow.component.grid.Grid.Column) Person(com.vaadin.flow.data.bean.Person) Grid(com.vaadin.flow.component.grid.Grid) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) Span(com.vaadin.flow.component.html.Span) HeaderCell(com.vaadin.flow.component.grid.HeaderRow.HeaderCell) Route(com.vaadin.flow.router.Route) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) Grid(com.vaadin.flow.component.grid.Grid) HeaderCell(com.vaadin.flow.component.grid.HeaderRow.HeaderCell) Person(com.vaadin.flow.data.bean.Person)

Example 7 with Column

use of com.vaadin.flow.component.grid.Grid.Column 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 8 with Column

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

the class TreeGridPreloadPage method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    Location location = event.getLocation();
    QueryParameters queryParameters = location.getQueryParameters();
    // query parameter: pageSize
    List<String> pageSize = queryParameters.getParameters().get("pageSize");
    if (pageSize != null) {
        grid.setPageSize(Integer.parseInt(pageSize.get(0)));
    }
    // query parameter: nodesPerLevel
    List<String> nodesPerLevel = queryParameters.getParameters().get("nodesPerLevel");
    // query parameter: depth
    List<String> depth = queryParameters.getParameters().get("depth");
    int dpNodesPerLevel = nodesPerLevel == null ? 3 : Integer.parseInt(nodesPerLevel.get(0));
    int dpDepth = depth == null ? 4 : Integer.parseInt(depth.get(0));
    setDataProvider(dpNodesPerLevel, dpDepth);
    // query parameter: expandedRootIndexes
    List<String> expandedRootIndexes = queryParameters.getParameters().get("expandedRootIndexes");
    if (expandedRootIndexes != null) {
        List<HierarchicalTestBean> expandedRootItems = Arrays.stream(expandedRootIndexes.get(0).split(",")).map(Integer::parseInt).map(expandedRootIndex -> new HierarchicalTestBean(null, 0, expandedRootIndex)).collect(java.util.stream.Collectors.toList());
        grid.expandRecursively(expandedRootItems, Integer.MAX_VALUE);
    }
    // query parameter: sortDirection
    List<String> sortDirection = queryParameters.getParameters().get("sortDirection");
    if (sortDirection != null) {
        SortDirection direction = SortDirection.valueOf(sortDirection.get(0).toUpperCase());
        GridSortOrderBuilder<HierarchicalTestBean> sorting = new GridSortOrderBuilder<HierarchicalTestBean>();
        Column<HierarchicalTestBean> column = grid.getColumns().get(0);
        if (direction == SortDirection.ASCENDING) {
            grid.sort(sorting.thenAsc(column).build());
        } else {
            grid.sort(sorting.thenDesc(column).build());
        }
    }
}
Also used : HierarchicalTestBean(com.vaadin.flow.data.bean.HierarchicalTestBean) Arrays(java.util.Arrays) SortDirection(com.vaadin.flow.data.provider.SortDirection) HasUrlParameter(com.vaadin.flow.router.HasUrlParameter) TextArea(com.vaadin.flow.component.textfield.TextArea) LitRenderer(com.vaadin.flow.data.renderer.LitRenderer) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) VaadinRequest(com.vaadin.flow.server.VaadinRequest) GridSortOrderBuilder(com.vaadin.flow.component.grid.GridSortOrderBuilder) BeforeEvent(com.vaadin.flow.router.BeforeEvent) HierarchicalQuery(com.vaadin.flow.data.provider.hierarchy.HierarchicalQuery) TreeGrid(com.vaadin.flow.component.treegrid.TreeGrid) Route(com.vaadin.flow.router.Route) OptionalParameter(com.vaadin.flow.router.OptionalParameter) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Column(com.vaadin.flow.component.grid.Grid.Column) Stream(java.util.stream.Stream) VaadinService(com.vaadin.flow.server.VaadinService) Location(com.vaadin.flow.router.Location) HierarchicalTestBean(com.vaadin.flow.data.bean.HierarchicalTestBean) TextField(com.vaadin.flow.component.textfield.TextField) QueryParameters(com.vaadin.flow.router.QueryParameters) QueryParameters(com.vaadin.flow.router.QueryParameters) GridSortOrderBuilder(com.vaadin.flow.component.grid.GridSortOrderBuilder) SortDirection(com.vaadin.flow.data.provider.SortDirection) Location(com.vaadin.flow.router.Location)

Example 9 with Column

use of com.vaadin.flow.component.grid.Grid.Column in project furms by unity-idm.

the class AuditLogView method createCommunityGrid.

private Grid<AuditLogGridModel> createCommunityGrid() {
    Grid<AuditLogGridModel> grid = new DenseGrid<>(AuditLogGridModel.class);
    Column<AuditLogGridModel> timestamp = grid.addComponentColumn(model -> {
        if (model.data.isEmpty())
            return new Div(new Label(model.timestamp.format(dateTimeFormatter)));
        Icon icon = grid.isDetailsVisible(model) ? ANGLE_DOWN.create() : ANGLE_RIGHT.create();
        return new Div(icon, new Label(model.timestamp.format(dateTimeFormatter)));
    }).setHeader(getTranslation("view.fenix-admin.audit-log.grid.1")).setSortable(true).setComparator(model -> model.timestamp);
    grid.addColumn(model -> model.originator).setHeader(getTranslation("view.fenix-admin.audit-log.grid.2")).setSortable(true).setComparator(model -> model.originator);
    grid.addColumn(model -> getTranslation("view.fenix-admin.audit-log.operation." + model.operation)).setHeader(getTranslation("view.fenix-admin.audit-log.grid.3")).setSortable(true).setComparator(comparing(model -> model.operation));
    grid.addColumn(model -> getTranslation("view.fenix-admin.audit-log.action." + model.action)).setHeader(getTranslation("view.fenix-admin.audit-log.grid.4")).setSortable(true).setComparator(comparing(model -> model.action));
    grid.addColumn(model -> model.name).setHeader(getTranslation("view.fenix-admin.audit-log.grid.5")).setSortable(true).setComparator(comparing(model -> model.name));
    grid.addColumn(model -> model.id).setHeader(getTranslation("view.fenix-admin.audit-log.grid.6")).setSortable(true).setComparator(comparing(model -> model.id));
    grid.sort(ImmutableList.of(new GridSortOrder<>(timestamp, SortDirection.DESCENDING)));
    grid.setItemDetailsRenderer(new ComponentRenderer<>(c -> AuditLogDetailsComponentFactory.create(c.data)));
    grid.setSelectionMode(Grid.SelectionMode.NONE);
    return grid;
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) UTCTimeUtils.convertToZoneTime(io.imunity.furms.utils.UTCTimeUtils.convertToZoneTime) SortDirection(com.vaadin.flow.data.provider.SortDirection) ZonedDateTime(java.time.ZonedDateTime) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) HashMap(java.util.HashMap) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent) AuditLogService(io.imunity.furms.api.audit_log.AuditLogService) FlexLayout(com.vaadin.flow.component.orderedlayout.FlexLayout) ImmutableList(com.google.common.collect.ImmutableList) DenseGrid(io.imunity.furms.ui.components.DenseGrid) MultiselectComboBox(org.vaadin.gatanaso.MultiselectComboBox) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Map(java.util.Map) Operation(io.imunity.furms.domain.audit_log.Operation) ANGLE_RIGHT(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_RIGHT) Comparator.comparing(java.util.Comparator.comparing) TypeReference(com.fasterxml.jackson.core.type.TypeReference) UserService(io.imunity.furms.api.users.UserService) Icon(com.vaadin.flow.component.icon.Icon) Action(io.imunity.furms.domain.audit_log.Action) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AuditLogDetailsComponentFactory(io.imunity.furms.ui.components.AuditLogDetailsComponentFactory) FURMSUser(io.imunity.furms.domain.users.FURMSUser) SearchLayout(io.imunity.furms.ui.components.administrators.SearchLayout) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ANGLE_DOWN(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_DOWN) GridSortOrder(com.vaadin.flow.component.grid.GridSortOrder) FurmsDateTimePicker(io.imunity.furms.ui.components.FurmsDateTimePicker) FenixAdminMenu(io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu) Column(com.vaadin.flow.component.grid.Grid.Column) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) DateTimeFormatter(java.time.format.DateTimeFormatter) Div(com.vaadin.flow.component.html.Div) GridSortOrder(com.vaadin.flow.component.grid.GridSortOrder) DenseGrid(io.imunity.furms.ui.components.DenseGrid) Label(com.vaadin.flow.component.html.Label) Icon(com.vaadin.flow.component.icon.Icon)

Example 10 with Column

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

the class GridColumnTest method addRegularColumnAndExtendedColumn.

@Test
public void addRegularColumnAndExtendedColumn() {
    ExtendedGrid<Person> extendedGrid = new ExtendedGrid<>();
    Column regularColumn = extendedGrid.addColumn(Person::toString);
    ExtendedColumn extendedColumn = extendedGrid.addColumn(TemplateRenderer.of(""), extendedGrid::createCustomColumn);
    assertEqualColumnClasses(regularColumn.getClass(), Column.class);
    assertEqualColumnClasses(extendedColumn.getClass(), ExtendedColumn.class);
}
Also used : Column(com.vaadin.flow.component.grid.Grid.Column) Test(org.junit.Test)

Aggregations

Column (com.vaadin.flow.component.grid.Grid.Column)13 Route (com.vaadin.flow.router.Route)11 Grid (com.vaadin.flow.component.grid.Grid)10 Person (com.vaadin.flow.data.bean.Person)7 Div (com.vaadin.flow.component.html.Div)6 TextField (com.vaadin.flow.component.textfield.TextField)6 Button (com.vaadin.flow.component.button.Button)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)4 Editor (com.vaadin.flow.component.grid.editor.Editor)4 Binder (com.vaadin.flow.data.binder.Binder)4 EmailValidator (com.vaadin.flow.data.validator.EmailValidator)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HeaderRow (com.vaadin.flow.component.grid.HeaderRow)3 Span (com.vaadin.flow.component.html.Span)3 WeakHashMap (java.util.WeakHashMap)3 SelectionMode (com.vaadin.flow.component.grid.Grid.SelectionMode)2 HeaderCell (com.vaadin.flow.component.grid.HeaderRow.HeaderCell)2