Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Add demo on styling grid with HasTheme #255

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/vaadin/flow/component/grid/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
@HtmlImport("frontend://bower_components/vaadin-checkbox/src/vaadin-checkbox.html")
@HtmlImport("frontend://flow-component-renderer.html")
@JavaScript("frontend://gridConnector.js")

public class Grid<T> extends Component
implements HasDataProvider<T>, HasStyle, HasSize, Focusable<Grid<T>>,
SortNotifier<Grid<T>, GridSortOrder<T>>, HasTheme {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/vaadin/flow/component/grid/demo/GridView.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ protected void initView() {
createDisabledGrid();
createBasicTreeGridUsage();
createLazyLoadingTreeGridUsage();
createGridWithStyling();

addCard("Grid example model",
new Label("These objects are used in the examples above"));
Expand Down Expand Up @@ -1082,6 +1083,21 @@ private void createDisabledGrid() {
addCard("Disabled grid", grid, div);
}

private void createGridWithStyling() {
// begin-source-example
// source-example-heading: Grid with styling
Grid<Person> grid = new Grid<>();
List<Person> people = createItems(50);
grid.setItems(people);

grid.addColumn(Person::getName).setHeader("Name");
grid.addColumn(Person::getAge).setHeader("Age");
grid.addThemeNames("no-border", "no-row-borders", "row-stripes");
// end-source-example
grid.setId("basic-grid-with-style");
addCard("Grid with styling", grid);
}

private Map<PersonWithLevel, List<PersonWithLevel>> childMap;

private void createBasicTreeGridUsage() {
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/vaadin/flow/component/grid/it/GridViewIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,18 @@ public void disabledGrid_itemsAreDisabled() {
button.isEnabled());
}

@Test
public void gridWithStyling_correctThemeAttribute() {
openTabAndCheckForErrors("");
GridElement grid = $(GridElement.class).id("basic-grid-with-style");
scrollToElement(grid);
waitUntil(driver -> grid.getAllColumns().size() == 2);

Assert.assertEquals("Grid should have the correct theme attribute.",
grid.getAttribute("theme"),
"no-row-borders no-border row-stripes");
}

private WebElement getCellContent(GridTHTDElement cell) {
return (WebElement) executeScript(
"return arguments[0].firstElementChild.assignedNodes()[0].firstElementChild;",
Expand Down