Class TableRow
- All Implemented Interfaces:
AttachNotifier,ClickNotifier<TableRow>,DetachNotifier,HasComponentsOfType<TableCell>,HasElement,HasEnabled,HasSize,HasStyle,Serializable
<tr> element ? a row of a
Table.
A <tr> may only contain <td> and
<th> cells, which is what HasComponentsOfType
expresses: the standard add, remove, replace and
bindChildren operations are all available, but only for TableCell,
so anything else is rejected at compile time. What this class adds on top are
the cell factories, which create a cell and attach it in one call. To put
arbitrary content in a row, put it inside a cell.
- Since:
- 25.3
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTableRow()Creates a new empty row.Creates a new row with the given content, following the rules ofaddCells(Component...).List equivalent ofTableRow(Component...). -
Method Summary
Modifier and TypeMethodDescriptionAppends the given components to this row.List equivalent ofaddCells(Component...).addColumnGroupHeaderCell(Component... content) Appends a header cell holding the given content and labelling the band of columns it heads, withscope="colgroup"set on the resulting<th>.addColumnGroupHeaderCell(Signal<String> textSignal) Appends a header cell labelling the band of columns it heads, withscope="colgroup"set on the resulting<th>and its text content following the given signal.Appends a header cell labelling the band of columns it heads, withscope="colgroup"set on the resulting<th>.addColumnGroupHeaderCell(String text, int colspan) Appends a header cell labelling the band of columns it heads, withscope="colgroup"and the givencolspanset on the resulting<th>, so that the cell reaches over the columns it names.addColumnHeaderCell(Component... content) Appends a header cell holding the given content and labelling the column it sits in, withscope="col"set on the resulting<th>.addColumnHeaderCell(Signal<String> textSignal) Appends a header cell labelling the column it sits in, withscope="col"set on the resulting<th>and its text content following the given signal.addColumnHeaderCell(String text) Appends a header cell labelling the column it sits in, withscope="col"set on the resulting<th>.addColumnHeaderCells(String... cellTexts) Appends a header cell for each of the given texts, each labelling the column it sits in withscope="col".addColumnHeaderCells(List<String> cellTexts) List equivalent ofaddColumnHeaderCells(String...).Appends a new empty data cell to this row.addDataCell(Component... content) Appends a new data cell holding the given content to this row, for a cell that is more than plain text.addDataCell(Signal<String> textSignal) Appends a new data cell whose text content follows the given signal.addDataCell(String text) Appends a new data cell with the given text to this row.addDataCells(String... cellTexts) Appends a sequence of data cells (<td>) with the given text contents to this row.addDataCells(List<String> cellTexts) List equivalent ofaddDataCells(String...).Appends a new empty header cell to this row.addHeaderCell(Component... content) Appends a new header cell holding the given content to this row, for a header that is more than plain text.addHeaderCell(Signal<String> textSignal) Appends a new header cell whose text content follows the given signal.addHeaderCell(String text) Appends a new header cell with the given text to this row.addHeaderCells(String... cellTexts) Appends a sequence of header cells (<th>) with the given text contents to this row.addHeaderCells(List<String> cellTexts) List equivalent ofaddHeaderCells(String...).addRowGroupHeaderCell(Component... content) Appends a header cell holding the given content and labelling the band of rows it heads, withscope="rowgroup"set on the resulting<th>.addRowGroupHeaderCell(Signal<String> textSignal) Appends a header cell labelling the band of rows it heads, withscope="rowgroup"set on the resulting<th>and its text content following the given signal.addRowGroupHeaderCell(String text) Appends a header cell labelling the band of rows it heads, withscope="rowgroup"set on the resulting<th>.addRowGroupHeaderCell(String text, int rowspan) Appends a header cell labelling the band of rows it heads, withscope="rowgroup"and the givenrowspanset on the resulting<th>, so that the cell reaches over the rows it names.addRowHeaderCell(Component... content) Appends a header cell holding the given content and labelling the row it leads, withscope="row"set on the resulting<th>.addRowHeaderCell(Signal<String> textSignal) Appends a header cell labelling the row it leads, withscope="row"set on the resulting<th>and its text content following the given signal.addRowHeaderCell(String text) Appends a header cell to this row that labels the row itself, withscope="row"set on the resulting<th>.getCells()Returns every cell of this row, in document order, both kinds combined.Returns the data cells of this row, in document order.Returns the header cells of this row, in document order.insertDataCell(int position) Inserts a new empty data cell at the given position.insertHeaderCell(int position) Inserts a new empty header cell at the given position.Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasComponentsOfType
add, add, addComponentAsFirst, addComponentAtIndex, bindChildren, getChildren, getComponentAt, getComponentCount, indexOf, remove, remove, removeAll, replaceMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
TableRow
public TableRow()Creates a new empty row. -
TableRow
Creates a new row with the given content, following the rules ofaddCells(Component...).- Parameters:
components- the cells, or the content to wrap in cells.
-
TableRow
List equivalent ofTableRow(Component...).- Parameters:
components- the cells, or the content to wrap in cells.
-
-
Method Details
-
addCells
Appends the given components to this row. ATableCellis added as-is; anything else is wrapped in a newTableDataCell, since a<tr>may only contain cells. This is the lenient counterpart of the inheritedadd(TableCell...), which takes cells only and rejects anything else at compile time.- Parameters:
components- the cells, or the content to wrap in cells.- Returns:
- this row, for fluent chaining.
-
addCells
List equivalent ofaddCells(Component...).- Parameters:
components- the cells, or the content to wrap in cells.- Returns:
- this row, for fluent chaining.
-
addDataCells
Appends a sequence of data cells (<td>) with the given text contents to this row.For example,
addDataCells("4.87", "12,104")renders as:<td>4.87</td> <td>12,104</td>- Parameters:
cellTexts- the text content for each data cell.- Returns:
- this row, for fluent chaining.
-
addDataCells
List equivalent ofaddDataCells(String...).- Parameters:
cellTexts- the text content for each data cell.- Returns:
- this row, for fluent chaining.
-
addHeaderCells
Appends a sequence of header cells (<th>) with the given text contents to this row.For example,
addHeaderCells("Mon", "Tue")renders as:<th>Mon</th> <th>Tue</th>- Parameters:
cellTexts- the text content for each header cell.- Returns:
- this row, for fluent chaining.
-
addHeaderCells
List equivalent ofaddHeaderCells(String...).- Parameters:
cellTexts- the text content for each header cell.- Returns:
- this row, for fluent chaining.
-
addColumnHeaderCells
Appends a header cell for each of the given texts, each labelling the column it sits in withscope="col". This is the bulk form ofaddColumnHeaderCell(String)and the usual way to fill a row in aTableHead.For example,
addColumnHeaderCells("Mon", "Tue")renders as:<th scope="col">Mon</th> <th scope="col">Tue</th>- Parameters:
cellTexts- the text content of the cells, one cell per entry.- Returns:
- this row, for chaining.
-
addColumnHeaderCells
List equivalent ofaddColumnHeaderCells(String...).- Parameters:
cellTexts- the text content of the cells, one cell per entry.- Returns:
- this row, for chaining.
-
addHeaderCell
Appends a new empty header cell to this row.- Returns:
- the new
<th>.
-
addHeaderCell
Appends a new header cell with the given text to this row. The cell carries noscope; useaddRowHeaderCell(String)oraddColumnHeaderCell(String)when the cell labels a row or a column.A span goes on the cell handed back, so
row.addHeaderCell("Animals").setColspan(2)is a single statement.- Parameters:
text- the text content.- Returns:
- the new
<th>.
-
addHeaderCell
Appends a new header cell whose text content follows the given signal.The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.
- Parameters:
textSignal- the signal to bind, notnull- Returns:
- the new
<th>.
-
addHeaderCell
Appends a new header cell holding the given content to this row, for a header that is more than plain text.- Parameters:
content- the content of the cell.- Returns:
- the new
<th>.
-
insertHeaderCell
Inserts a new empty header cell at the given position.- Parameters:
position- the position to insert the cell at, between 0 and the number of cells in this row.- Returns:
- the new
<th>.
-
addRowHeaderCell
Appends a header cell to this row that labels the row itself, withscope="row"set on the resulting<th>. This is a shortcut for the common pattern of using a leading<th>as a row label, which assistive technologies announce as the header for the data cells in the same row.For example,
addRowHeaderCell("Breed")renders as:<th scope="row">Breed</th>There is no overload taking a span, because a span goes on the cell handed back ?
row.addRowHeaderCell("Horse").setRowspan(2)? and because it would be ambiguous which of the two spans anintmeant.addRowGroupHeaderCell(String, int)andaddColumnGroupHeaderCell(String, int)do take one: there the span is what makes the cell a group header rather than decoration on it.- Parameters:
text- the text content.- Returns:
- the new
<th>withscope="row".
-
addRowHeaderCell
Appends a header cell labelling the row it leads, withscope="row"set on the resulting<th>and its text content following the given signal.The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.
- Parameters:
textSignal- the signal to bind, notnull- Returns:
- the new
<th>withscope="row".
-
addRowHeaderCell
Appends a header cell holding the given content and labelling the row it leads, withscope="row"set on the resulting<th>. This is the content-taking form ofaddRowHeaderCell(String), for a label that is not plain text.For example,
addRowHeaderCell(new Span("Breed"))renders as:<th scope="row"><span>Breed</span></th>- Parameters:
content- the content of the cell.- Returns:
- the new
<th>withscope="row".
-
addColumnHeaderCell
Appends a header cell labelling the column it sits in, withscope="col"set on the resulting<th>. This is the counterpart ofaddRowHeaderCell(String)and the usual shape of a cell in aTableHead.For example,
addColumnHeaderCell("Name")renders as:<th scope="col">Name</th>A span goes on the cell handed back, as it does for
addRowHeaderCell(String); a header that spans the columns it names is usually better expressed withaddColumnGroupHeaderCell(String, int).- Parameters:
text- the text content.- Returns:
- the new
<th>withscope="col".
-
addColumnHeaderCell
Appends a header cell labelling the column it sits in, withscope="col"set on the resulting<th>and its text content following the given signal.The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.
- Parameters:
textSignal- the signal to bind, notnull- Returns:
- the new
<th>withscope="col".
-
addColumnHeaderCell
Appends a header cell holding the given content and labelling the column it sits in, withscope="col"set on the resulting<th>. This is the content-taking form ofaddColumnHeaderCell(String), for a label that is not plain text.For example,
addColumnHeaderCell(new Span("Name"))renders as:<th scope="col"><span>Name</span></th>- Parameters:
content- the content of the cell.- Returns:
- the new
<th>withscope="col".
-
addRowGroupHeaderCell
Appends a header cell labelling the band of rows it heads, withscope="rowgroup"set on the resulting<th>. Use it for the cell that names a group of consecutive rows, such as "Terrestrial planets" in front of the four rows describing them, as opposed toaddRowHeaderCell(String), which labels one row.For example,
addRowGroupHeaderCell("Dwarf planets")renders as:<th scope="rowgroup">Dwarf planets</th>- Parameters:
text- the text content.- Returns:
- the new
<th>withscope="rowgroup".
-
addRowGroupHeaderCell
Appends a header cell labelling the band of rows it heads, withscope="rowgroup"set on the resulting<th>and its text content following the given signal. Set the span on the returned cell withTableCell.setRowspan(int).The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.
- Parameters:
textSignal- the signal to bind, notnull- Returns:
- the new
<th>withscope="rowgroup".
-
addRowGroupHeaderCell
Appends a header cell holding the given content and labelling the band of rows it heads, withscope="rowgroup"set on the resulting<th>. This is the content-taking form ofaddRowGroupHeaderCell(String); set the span on the returned cell withTableCell.setRowspan(int), since a varargs parameter has to come last and so cannot be combined with one in a single call.For example,
addRowGroupHeaderCell(new Span("Gas giants"))renders as:<th scope="rowgroup"><span>Gas giants</span></th>- Parameters:
content- the content of the cell.- Returns:
- the new
<th>withscope="rowgroup".
-
addRowGroupHeaderCell
Appends a header cell labelling the band of rows it heads, withscope="rowgroup"and the givenrowspanset on the resulting<th>, so that the cell reaches over the rows it names.For example,
addRowGroupHeaderCell("Terrestrial planets", 4)renders as:<th scope="rowgroup" rowspan="4">Terrestrial planets</th>- Parameters:
text- the text content.rowspan- the number of rows the header covers, or0to cover the rest of the row group.- Returns:
- the new
<th>withscope="rowgroup". - Throws:
IllegalArgumentException- ifrowspanis negative.
-
addColumnGroupHeaderCell
Appends a header cell labelling the band of columns it heads, withscope="colgroup"set on the resulting<th>. This is the counterpart ofaddRowGroupHeaderCell(String), for a cell that names a group of consecutive columns rather than a single one.For example,
addColumnGroupHeaderCell("Measurements")renders as:<th scope="colgroup">Measurements</th>- Parameters:
text- the text content.- Returns:
- the new
<th>withscope="colgroup".
-
addColumnGroupHeaderCell
Appends a header cell labelling the band of columns it heads, withscope="colgroup"set on the resulting<th>and its text content following the given signal. Set the span on the returned cell withTableCell.setColspan(int).The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.
- Parameters:
textSignal- the signal to bind, notnull- Returns:
- the new
<th>withscope="colgroup".
-
addColumnGroupHeaderCell
Appends a header cell holding the given content and labelling the band of columns it heads, withscope="colgroup"set on the resulting<th>. This is the content-taking form ofaddColumnGroupHeaderCell(String); set the span on the returned cell withTableCell.setColspan(int), since a varargs parameter has to come last and so cannot be combined with one in a single call.For example,
addColumnGroupHeaderCell(new Span("Measurements"))renders as:<th scope="colgroup"><span>Measurements</span></th>- Parameters:
content- the content of the cell.- Returns:
- the new
<th>withscope="colgroup".
-
addColumnGroupHeaderCell
Appends a header cell labelling the band of columns it heads, withscope="colgroup"and the givencolspanset on the resulting<th>, so that the cell reaches over the columns it names.For example,
addColumnGroupHeaderCell("Measurements", 3)renders as:<th scope="colgroup" colspan="3">Measurements</th>- Parameters:
text- the text content.colspan- the number of columns the header covers.- Returns:
- the new
<th>withscope="colgroup". - Throws:
IllegalArgumentException- ifcolspanis less than 1.
-
addDataCell
Appends a new empty data cell to this row.- Returns:
- the new
<td>.
-
addDataCell
Appends a new data cell with the given text to this row.- Parameters:
text- the text content.- Returns:
- the new
<td>.
-
addDataCell
Appends a new data cell whose text content follows the given signal.The cell follows the signal for as long as it is attached, so this is the factory to use for a value that is reactive rather than fixed.
- Parameters:
textSignal- the signal to bind, notnull- Returns:
- the new
<td>.
-
addDataCell
Appends a new data cell holding the given content to this row, for a cell that is more than plain text.- Parameters:
content- the content of the cell.- Returns:
- the new
<td>.
-
insertDataCell
Inserts a new empty data cell at the given position.- Parameters:
position- the position to insert the cell at, between 0 and the number of cells in this row.- Returns:
- the new
<td>.
-
getHeaderCells
Returns the header cells of this row, in document order.- Returns:
- this row's
<th>cells.
-
getDataCells
Returns the data cells of this row, in document order.- Returns:
- this row's
<td>cells.
-
getCells
Returns every cell of this row, in document order, both kinds combined. This is the typed counterpart ofComponent.getChildren(). For kind-specific lists usegetHeaderCells()orgetDataCells().- Returns:
- this row's cells.
-