Class Table
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.ClickNotifier<Table>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasAriaLabel,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,Serializable
<table> element.
Unlike the deprecated NativeTable, this component does not extend
HtmlContainer, so it has no generic
add(Component). A <table> may only contain a
<caption>, <colgroup>, <thead>, <tbody> and
<tfoot>, and those are reached through the accessors below, which
also keep them in the order the WHATWG HTML specification requires.
- Since:
- 25.3
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddBody()Appends a new<tbody>to this table, after any bodies it already has and before the<tfoot>.Appends the given<tbody>to this table, after any bodies it already has and before the<tfoot>.addCaption(com.vaadin.flow.component.Component... components) Appends the given components to this table's caption, creating it if none exists yet.addCaption(List<? extends com.vaadin.flow.component.Component> components) List equivalent ofaddCaption(Component...).Appends a new empty<colgroup>to this table, after the caption and any column groups it already has, and before the<thead>.addColumnGroup(TableColumn... columns) Appends a new<colgroup>holding the given columns to this table.addColumnGroup(TableColumnGroup group) Appends the given<colgroup>to this table.addColumnGroup(List<? extends TableColumn> columns) List equivalent ofaddColumnGroup(TableColumn...).Appends a new empty row to this table's<tfoot>, creating it if the table has none.addFooterRow(String... cellTexts) Appends a row of data cells with the given texts to this table's<tfoot>.addFooterRow(List<String> cellTexts) List equivalent ofaddFooterRow(String...).voidaddFooterRows(TableRow... rows) Appends the given rows to this table's<tfoot>.voidaddFooterRows(List<? extends TableRow> rows) List equivalent ofaddFooterRows(TableRow...).Appends a new empty row to this table's<thead>, creating it if the table has none.addHeaderRow(String... cellTexts) Appends a row of header cells with the given texts to this table's<thead>.addHeaderRow(List<String> cellTexts) List equivalent ofaddHeaderRow(String...).voidaddHeaderRows(TableRow... rows) Appends the given rows to this table's<thead>.voidaddHeaderRows(List<? extends TableRow> rows) List equivalent ofaddHeaderRows(TableRow...).addRow()Appends a new empty row to this table's<tbody>, creating the body if the table has none.Appends a row of data cells with the given texts to this table's<tbody>.List equivalent ofaddRow(String...).voidAppends the given rows to this table's<tbody>.voidList equivalent ofaddRows(TableRow...).addRowWithHeader(String header, String... cellTexts) Appends a row led by a header cell labelling it, followed by data cells with the given texts.addRowWithHeader(String header, List<String> cellTexts) List equivalent ofaddRowWithHeader(String, String...).Returns every row of this table, walking its sections in document order: the<thead>rows, then the rows of each<tbody>, then the<tfoot>rows.Returns the<tbody>elements of this table, in document order.getBody()Returns the first<tbody>of this table, creating one if the table has none.Returns this table's caption, creating one if the table has none.@Nullable StringReturns the text content of this table's caption, ornullif the table has no caption or the caption holds something other than text.Returns the column groups of this table, in document order.getFoot()Returns this table's<tfoot>, creating one if the table has none.getHead()Returns this table's<thead>, creating one if the table has none.booleanReports whether this table already has a<caption>.booleanhasFoot()Reports whether this table already has a<tfoot>.booleanhasHead()Reports whether this table already has a<thead>.voidRemoves every row from this table, leaving its sections in place.voidremoveBody(TableBody body) Removes the given<tbody>from this table.voidRemoves this table's caption, if it has one.voidRemoves the given column group from this table.voidRemoves this table's<tfoot>, if it has one.voidRemoves this table's<thead>, if it has one.voidsetCaption(@Nullable TableCaption caption) Puts the given caption on this table, replacing the one it already has, if any.voidsetCaptionText(@Nullable String text) Sets the text content of this table's caption, creating the caption if the table has none.voidPuts the given<tfoot>on this table, replacing the one it already has, if any.voidPuts the given<thead>on this table, replacing the one it already has, if any.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.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods 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
-
Table
public Table()Creates a new empty table.
-
-
Method Details
-
getCaption
Returns this table's caption, creating one if the table has none.- Returns:
- the table's
<caption>.
-
hasCaption
public boolean hasCaption()Reports whether this table already has a<caption>. UnlikegetCaption(), this does not create one.- Returns:
trueif the table has a caption.
-
getCaptionText
Returns the text content of this table's caption, ornullif the table has no caption or the caption holds something other than text. UnlikegetCaption(), this does not create one.A caption assembled from components has no faithful text representation, and reporting whichever text nodes happen to sit around those components would be misleading, so
nullis returned instead. UsehasCaption()to tell a table with no caption from one whose caption holds markup.- Returns:
- the caption text, or
nullif there is none to report.
-
setCaptionText
Sets the text content of this table's caption, creating the caption if the table has none.Passing
nullremoves the caption, assetCaption(TableCaption)does, so that whatevergetCaptionText()reports can be handed straight back.- Parameters:
text- the caption text, ornullto remove the caption.
-
setCaption
Puts the given caption on this table, replacing the one it already has, if any.- Parameters:
caption- the caption to use, ornullto remove the one the table has.
-
addCaption
Appends the given components to this table's caption, creating it if none exists yet. Useful for richer captions containing inline markup.- Parameters:
components- the components to append.- Returns:
- the caption.
-
addCaption
List equivalent ofaddCaption(Component...).- Parameters:
components- the components to append.- Returns:
- the caption.
-
removeCaption
public void removeCaption()Removes this table's caption, if it has one. -
addColumnGroup
Appends a new empty<colgroup>to this table, after the caption and any column groups it already has, and before the<thead>.- Returns:
- the new column group.
-
addColumnGroup
Appends the given<colgroup>to this table.- Parameters:
group- the column group to add.- Returns:
- the given group, for chaining.
-
addColumnGroup
Appends a new<colgroup>holding the given columns to this table.- Parameters:
columns- the columns the new group should hold.- Returns:
- the new column group.
-
addColumnGroup
List equivalent ofaddColumnGroup(TableColumn...).- Parameters:
columns- the columns the new group should hold.- Returns:
- the new column group.
-
getColumnGroups
Returns the column groups of this table, in document order.- Returns:
- the table's
<colgroup>elements.
-
removeColumnGroup
Removes the given column group from this table.- Parameters:
group- the column group to remove.
-
getHead
Returns this table's<thead>, creating one if the table has none.- Returns:
- the table's
<thead>.
-
hasHead
public boolean hasHead()Reports whether this table already has a<thead>. UnlikegetHead(), this does not create one.- Returns:
trueif the table has a head.
-
setHead
Puts the given<thead>on this table, replacing the one it already has, if any.- Parameters:
head- the head to use, ornullto remove the one the table has.
-
removeHead
public void removeHead()Removes this table's<thead>, if it has one. -
getFoot
Returns this table's<tfoot>, creating one if the table has none.- Returns:
- the table's
<tfoot>.
-
hasFoot
public boolean hasFoot()Reports whether this table already has a<tfoot>. UnlikegetFoot(), this does not create one.- Returns:
trueif the table has a foot.
-
setFoot
Puts the given<tfoot>on this table, replacing the one it already has, if any.- Parameters:
foot- the foot to use, ornullto remove the one the table has.
-
removeFoot
public void removeFoot()Removes this table's<tfoot>, if it has one. -
getBodies
Returns the<tbody>elements of this table, in document order. A table may have several.- Returns:
- the table's bodies.
-
getBody
Returns the first<tbody>of this table, creating one if the table has none.- Returns:
- the table's first body.
-
addBody
Appends a new<tbody>to this table, after any bodies it already has and before the<tfoot>.- Returns:
- the new body.
-
addBody
Appends the given<tbody>to this table, after any bodies it already has and before the<tfoot>.- Parameters:
body- the body to add.- Returns:
- the given body, for chaining.
-
removeBody
Removes the given<tbody>from this table.- Parameters:
body- the body to remove.
-
getAllRows
Returns every row of this table, walking its sections in document order: the<thead>rows, then the rows of each<tbody>, then the<tfoot>rows.The name says
Allbecause this is the only row accessor that crosses sections:TableRowContainer.getRows(),TableRowContainer.getRows()andTableRowContainer.getRows()each return the rows of one container, andaddRow()appends to the body.- Returns:
- all the rows of this table.
-
removeAllRows
public void removeAllRows()Removes every row from this table, leaving its sections in place. -
addRow
Appends a new empty row to this table's<tbody>, creating the body if the table has none. This mirrors what a browser does with a<tr>written straight inside a<table>. UseaddHeaderRow()oraddFooterRow()for the other sections; note thatgetAllRows()spans all three.- Returns:
- the new row.
-
addRow
Appends a row of data cells with the given texts to this table's<tbody>.- Parameters:
cellTexts- the text content for each data cell.- Returns:
- the new row.
-
addRow
List equivalent ofaddRow(String...).- Parameters:
cellTexts- the text content for each data cell.- Returns:
- the new row.
-
addRowWithHeader
Appends a row led by a header cell labelling it, followed by data cells with the given texts. The leading cell is a<th scope="row">, which is what lets assistive technology announce the right label for each data cell in the row.- Parameters:
header- the text of the leading header cell.cellTexts- the text content for each data cell after it.- Returns:
- the new row.
-
addRowWithHeader
List equivalent ofaddRowWithHeader(String, String...).- Parameters:
header- the text of the leading header cell.cellTexts- the text content for each data cell after it.- Returns:
- the new row.
-
addRows
Appends the given rows to this table's<tbody>.- Parameters:
rows- the rows to add.
-
addRows
List equivalent ofaddRows(TableRow...).- Parameters:
rows- the rows to add.
-
addHeaderRow
Appends a new empty row to this table's<thead>, creating it if the table has none.- Returns:
- the new row.
-
addHeaderRow
Appends a row of header cells with the given texts to this table's<thead>.- Parameters:
cellTexts- the text content for each header cell.- Returns:
- the new row.
-
addHeaderRow
List equivalent ofaddHeaderRow(String...).- Parameters:
cellTexts- the text content for each header cell.- Returns:
- the new row.
-
addHeaderRows
Appends the given rows to this table's<thead>.- Parameters:
rows- the rows to add.
-
addHeaderRows
List equivalent ofaddHeaderRows(TableRow...).- Parameters:
rows- the rows to add.
-