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