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);
}
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);
}
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());
}
}
}
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;
}
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);
}
Aggregations