use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class GridWithTemplatePage method createGridInATemplateWithTemplatesInTheCells.
private void createGridInATemplateWithTemplatesInTheCells() {
GridInATemplate gridInATemplate = new GridInATemplate();
gridInATemplate.setId("injected-template-in-cells");
Grid<String> grid = gridInATemplate.getGrid();
setCommonGridFeatures(grid, gridInATemplate.getId().get());
grid.addColumn(value -> value);
grid.addColumn(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get())));
add(new H3("Grid with templates in the cells"), gridInATemplate);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class GridWithTemplatePage method createGridInTemplateWithColumnProperties.
private void createGridInTemplateWithColumnProperties() {
GridInATemplate gridInATemplate = new GridInATemplate();
gridInATemplate.setId("injected-columns-with-properties");
Grid<String> grid = gridInATemplate.getGrid();
setCommonGridFeatures(grid, gridInATemplate.getId().get());
grid.addColumn(value -> value).setFlexGrow(2);
grid.addColumn(TemplateRenderer.of("[[index]]")).setFlexGrow(0).setWidth("20px");
grid.addColumn(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get()))).setFrozen(true).setResizable(true);
add(new H3("Grid with column properties"), gridInATemplate);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer 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);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer 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.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class TreeComponentColumnsPage method addTreeGrid.
private void addTreeGrid(boolean addGridBefore) {
TreeGrid<String> grid = new TreeGrid<>();
if (addGridBefore) {
grid.setId("grid-then-comp");
add(grid);
}
ComponentRenderer<TextField, String> componentRenderer = new ComponentRenderer<>(TextField::new, (component, item) -> {
component.setReadOnly(true);
component.setValue(item);
});
grid.addComponentHierarchyColumn(this::createTextField).setHeader("Header A").setId("textfield");
grid.addColumn(componentRenderer).setHeader("Header B");
ComponentRenderer<Button, String> componentRendererBtn = new ComponentRenderer<>(() -> new Button("btn"), ((button, s) -> {
button.setText(s);
button.setThemeName(ButtonVariant.LUMO_ERROR.getVariantName());
}));
grid.addColumn(componentRendererBtn).setHeader("Header C");
TreeData<String> data = new TreeData<>();
final Map<String, String> parentPathMap = new HashMap<>();
addRootItems("Granddad", 3, data, parentPathMap).forEach(granddad -> addItems("Dad", 3, granddad, data, parentPathMap).forEach(dad -> addItems("Son", 100, dad, data, parentPathMap)));
grid.setDataProvider(new TreeDataProvider<>(data));
if (!addGridBefore) {
grid.setId("comp-then-grid");
add(grid);
}
}
Aggregations