Search in sources :

Example 6 with HeaderCell

use of com.vaadin.flow.component.grid.HeaderRow.HeaderCell in project flow-components by vaadin.

the class HeaderFooterTest method joinTwoLastHeaderCells.

@Test
public void joinTwoLastHeaderCells() {
    HeaderRow bottom = grid.prependHeaderRow();
    HeaderRow top = grid.prependHeaderRow();
    HeaderCell firstCell = top.getCells().get(0);
    HeaderCell joined = top.join(secondColumn, thirdColumn);
    List<List<Element>> layers = getColumnLayersAndAssertCount(2);
    assertRowWrapsLayer(bottom, layers.get(0));
    assertRowWrapsLayer(top, layers.get(1));
    Assert.assertEquals("HeaderRow should have two cells after joining two of three cells", 2, top.getCells().size());
    Assert.assertEquals("The joined cell should be the last cell of the row after joining two last cells", joined, top.getCells().get(1));
    Assert.assertEquals("The first cell should not be affected after joining two last cells", firstCell, top.getCells().get(0));
}
Also used : HeaderCell(com.vaadin.flow.component.grid.HeaderRow.HeaderCell) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with HeaderCell

use of com.vaadin.flow.component.grid.HeaderRow.HeaderCell in project flow-components by vaadin.

the class HeaderFooterTest method joinTwoFirstHeaderCellsOnLowerLayer_layerMovedToTop.

@Test
public void joinTwoFirstHeaderCellsOnLowerLayer_layerMovedToTop() {
    grid.appendFooterRow();
    grid.prependHeaderRow();
    FooterRow footer = grid.appendFooterRow();
    HeaderRow header = grid.prependHeaderRow();
    HeaderCell lastCell = header.getCells().get(2);
    List<List<Element>> layers = getColumnLayersAndAssertCount(3);
    assertRowWrapsLayer(header, layers.get(1), 3);
    assertRowWrapsLayer(footer, layers.get(2), 3);
    header.join(firstColumn, secondColumn);
    layers = getColumnLayersAndAssertCount(3);
    assertRowWrapsLayer(footer, layers.get(1), 3);
    assertRowWrapsLayer(header, layers.get(2), 2);
    Assert.assertEquals("The last cell should not be affected after joining two first cells", lastCell, header.getCells().get(1));
}
Also used : HeaderCell(com.vaadin.flow.component.grid.HeaderRow.HeaderCell) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with HeaderCell

use of com.vaadin.flow.component.grid.HeaderRow.HeaderCell in project flow-components by vaadin.

the class GridViewHeaderAndFooterRowsPage method createHeaderAndFooterUsingComponents.

private void createHeaderAndFooterUsingComponents() {
    Grid<Person> grid = new Grid<>();
    grid.setItems(getItems());
    Column<Person> nameColumn = grid.addColumn(Person::getFirstName).setHeader(new Span("Name")).setComparator((p1, p2) -> p1.getFirstName().compareToIgnoreCase(p2.getFirstName()));
    Column<Person> ageColumn = grid.addColumn(Person::getAge, "age").setHeader(new Span("Age"));
    Column<Person> streetColumn = grid.addColumn(person -> person.getAddress().getStreet()).setHeader(new Span("Street"));
    Column<Person> postalCodeColumn = grid.addColumn(person -> person.getAddress().getPostalCode()).setHeader(new Span("Postal Code"));
    HeaderRow topRow = grid.prependHeaderRow();
    HeaderCell informationCell = topRow.join(nameColumn, ageColumn);
    informationCell.setComponent(new Span("Basic Information"));
    HeaderCell addressCell = topRow.join(streetColumn, postalCodeColumn);
    addressCell.setComponent(new Span("Address Information"));
    grid.appendFooterRow().getCell(nameColumn).setComponent(new Span("Total: " + getItems().size() + " people"));
    grid.setId("grid-header-with-components");
    addCard("Header and footer rows", "Header and footer using components", 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) Span(com.vaadin.flow.component.html.Span)

Aggregations

HeaderCell (com.vaadin.flow.component.grid.HeaderRow.HeaderCell)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Grid (com.vaadin.flow.component.grid.Grid)2 Column (com.vaadin.flow.component.grid.Grid.Column)2 HeaderRow (com.vaadin.flow.component.grid.HeaderRow)2 Span (com.vaadin.flow.component.html.Span)2 Person (com.vaadin.flow.data.bean.Person)2 Route (com.vaadin.flow.router.Route)2