Class TableCell
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasComponents,HasComponentsOfType<Component>,HasElement,HasEnabled,HasSize,HasStyle,HasText,Serializable
- Direct Known Subclasses:
TableDataCell,TableHeaderCell
TableRow can hold: a
TableDataCell (<td>) and a TableHeaderCell
(<th>). It exists so that operations that do not care
which kind a cell is ? TableRow.getCells() and the row's inherited
add and remove ? have a type to speak in.
Cells hold flow content, so this class does extend HtmlContainer:
anything may go inside a cell.
- Since:
- 25.3
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thecolspanattribute.Returns the ids of the header cells associated with this cell via theheadersattribute, in the order they appear, or an empty list if the attribute is not set.intReturns the value of therowspanattribute.booleanReports whether this cell carries an explicitcolspan, as opposed to falling back to the default of 1.booleanReports whether this cell carries an explicitrowspan, as opposed to falling back to the default of 1.voidResets the colspan to its default value of 1.voidRemoves theheadersattribute from this cell.voidResets the rowspan to its default value of 1.voidsetColspan(int colspan) Sets thecolspanattribute ? how many columns this cell spans.voidsetHeaderIds(String @Nullable ... ids) Sets theheadersattribute ? a list of ids referring to the<th>cells that label this cell.voidsetHeaderIds(@Nullable List<String> ids) List equivalent ofsetHeaderIds(String...).voidsetHeaders(TableHeaderCell @Nullable ... headerCells) Convenience overload that takes header cells directly and uses theiridattributes.voidsetHeaders(@Nullable List<? extends TableHeaderCell> headerCells) List equivalent ofsetHeaders(TableHeaderCell...).voidsetRowspan(int rowspan) Sets therowspanattribute ? how many rows this cell spans.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.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasComponents
addMethods 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, setClassNameMethods inherited from interface com.vaadin.flow.component.HasText
bindText, getText, getWhiteSpace, setText, setWhiteSpace
-
Constructor Details
-
TableCell
protected TableCell()Creates a new empty cell. -
TableCell
Creates a new cell with the given children.- Parameters:
components- the children components.
-
TableCell
List equivalent ofTableCell(Component...).- Parameters:
components- the children components.
-
-
Method Details
-
setColspan
public void setColspan(int colspan) Sets thecolspanattribute ? how many columns this cell spans. The default is1.Unlike
setRowspan(int), zero is not allowed: the "span the rest of the column group" meaning it once had was dropped from HTML, and browsers now clamp it back to1. Browsers likewise clamp values above 1000 down to 1000 when laying the table out; the value is written through and read back verbatim here.- Parameters:
colspan- a positive integer.- Throws:
IllegalArgumentException- ifcolspanis less than 1.
-
getColspan
public int getColspan()Returns the value of thecolspanattribute. A cell with nocolspancovers one column, so this reports 1 for it; usehasColspan()to tell that apart from an explicitcolspan="1".- Returns:
- the current colspan. Default is 1.
-
hasColspan
public boolean hasColspan()Reports whether this cell carries an explicitcolspan, as opposed to falling back to the default of 1.- Returns:
trueif the attribute is set.
-
resetColspan
public void resetColspan()Resets the colspan to its default value of 1. -
setRowspan
public void setRowspan(int rowspan) Sets therowspanattribute ? how many rows this cell spans. The default is1.Zero is allowed and still means something in HTML: the cell extends to the end of the row group (
<thead>,<tbody>or<tfoot>, even an implicit one) it belongs to. Browsers clamp values above 65534 down to 65534 when laying the table out; the value is written through and read back verbatim here.- Parameters:
rowspan- a non-negative integer, where 0 spans the rest of the row group.- Throws:
IllegalArgumentException- ifrowspanis negative.
-
getRowspan
public int getRowspan()Returns the value of therowspanattribute. A cell with norowspancovers one row, so this reports 1 for it; usehasRowspan()to tell that apart from an explicitrowspan="1".- Returns:
- the current rowspan. Default is 1.
-
hasRowspan
public boolean hasRowspan()Reports whether this cell carries an explicitrowspan, as opposed to falling back to the default of 1. Note thatrowspan="0", which reaches to the end of the row group, is an explicit span even thoughgetRowspan()reports 0 rather than a row count.- Returns:
trueif the attribute is set.
-
resetRowspan
public void resetRowspan()Resets the rowspan to its default value of 1. -
setHeaderIds
Sets theheadersattribute ? a list of ids referring to the<th>cells that label this cell. Assistive technologies use it to read out the right headers when navigating complex tables, wherescopealone isn't enough to disambiguate.An empty array removes the attribute, as does
resetHeaders().- Parameters:
ids- the ids of the header cells, in any order. None may be blank or contain whitespace.- Throws:
IllegalArgumentException- if an id is blank or contains whitespace.
-
setHeaderIds
List equivalent ofsetHeaderIds(String...). An empty list (ornull) clears the attribute.- Parameters:
ids- the ids of the header cells, in any order. None may be blank or contain whitespace.- Throws:
IllegalArgumentException- if an id is blank or contains whitespace.
-
setHeaders
Convenience overload that takes header cells directly and uses theiridattributes. Each cell must have an id set.- Parameters:
headerCells- the header cells whose ids should be referenced.- Throws:
IllegalArgumentException- if any of the given cells does not have an id set.
-
setHeaders
List equivalent ofsetHeaders(TableHeaderCell...).- Parameters:
headerCells- the header cells whose ids should be referenced.- Throws:
IllegalArgumentException- if any of the given cells does not have an id set.
-
getHeaderIds
Returns the ids of the header cells associated with this cell via theheadersattribute, in the order they appear, or an empty list if the attribute is not set.- Returns:
- the header ids, never
null.
-
resetHeaders
public void resetHeaders()Removes theheadersattribute from this cell.
-