Class Table

  • All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, Serializable, TableRowContainer

    @Tag("table")
    public class Table
    extends com.vaadin.flow.component.HtmlComponent
    implements TableRowContainer
    Represents the html table element (<table>). Can contain
    • a caption
    • a column group
    • a thead
    • a tfoot
    • a tbody or a set of table rows


    Sub elements except for rows are created when calling the respective getter, for instance getHead(). Since <table> expects a certain order of elements, this class takes care of positioning them in the correct order (e.g. head <thead>, then <tbody> and then <tfoot>, etc).

    Also a table must not contain rows as direct children, when having a <tbody>. Therefore, all previously to the table assigned rows are automatically assigned to the <tbody>, when getBody() is called.

    Also all subsequent calls to any table row method are automatically delegated to the <tbody>.
    Author:
    Stefan Uebe
    See Also:
    TableCaption, TableColumnGroup, TableRow, TableHead, TableBody, TableFoot, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Table()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TableRow addRow()
      Adds a single row instance to this container.
      TableRow[] addRows​(int rows)
      Adds multiple rows to this instance based on the given integer (must be greater than 0).
      void addRows​(TableRow... rows)
      Adds the given list of rows.
      TableBody getBody()
      Returns the TableBody for this instance.
      TableCaption getCaption()
      Returns the TableCaption for this instance.
      TableColumnGroup getColumnGroup()
      Returns the TableColumnGroup for this instance.
      TableFoot getFoot()
      Returns the TableFoot for this instance.
      TableHead getHead()
      Returns the TableHead for this instance.
      TableRow insertRow​(int index)
      Inserts a single row instance at the given index to this container.
      void insertRows​(int index, TableRow... rows)
      Inserts the given rows at the given index to this instance.
      void removeAllRows()
      Removes all rows.
      void removeBody()
      Removes the body instance from this table.
      void removeCaption()
      Removes the caption instance from this table.
      void removeColumnGroup()
      Removes the column group instance from this table.
      void removeFoot()
      Removes the foot instance from this table.
      void removeHead()
      Removes the head instance from this table.
      void removeRow​(int index)
      Removes the row with the given index.
      void removeRows​(TableRow... rows)
      Removes the given rows from this instance.
      void replaceRow​(int index, TableRow row)
      Replaces a single row instance to the given index in this container and replaces the existing row.
      void setRow​(int index, TableRow row)
      Replaces a single row instance to the given index in this container and replaces the existing row.
      Stream<TableRow> streamRows()
      Returns the rows of this instance as a stream.
      • Methods inherited from class com.vaadin.flow.component.HtmlComponent

        getTitle, setTitle
      • Methods inherited from class com.vaadin.flow.component.Component

        addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
      • Methods inherited from interface com.vaadin.flow.component.AttachNotifier

        addAttachListener
      • Methods inherited from interface com.vaadin.flow.component.DetachNotifier

        addDetachListener
      • Methods inherited from interface com.vaadin.flow.component.HasElement

        getElement
      • Methods inherited from interface com.vaadin.flow.component.HasSize

        getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
      • Methods inherited from interface com.vaadin.flow.component.HasStyle

        addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
    • Constructor Detail

      • Table

        public Table()
    • Method Detail

      • getCaption

        public TableCaption getCaption()
        Returns the TableCaption for this instance. Creates a new instance on the first call.
        Returns:
        caption
      • getColumnGroup

        public TableColumnGroup getColumnGroup()
        Returns the TableColumnGroup for this instance. Creates a new instance on the first call.
        Returns:
        column group
      • getHead

        public TableHead getHead()
        Returns the TableHead for this instance. Creates a new instance on the first call.
        Returns:
        table head
      • removeHead

        public void removeHead()
        Removes the head instance from this table.

        Does not move any rows from the head to the table itself. That has to be done manually.
      • removeFoot

        public void removeFoot()
        Removes the foot instance from this table.

        Does not move any rows from the foot to the table itself. That has to be done manually.
      • removeBody

        public void removeBody()
        Removes the body instance from this table.

        Does not move any rows from the body to the table itself. That has to be done manually.
      • removeCaption

        public void removeCaption()
        Removes the caption instance from this table.
      • removeColumnGroup

        public void removeColumnGroup()
        Removes the column group instance from this table.
      • getBody

        public TableBody getBody()
        Returns the TableBody for this instance. Creates a new instance on the first call.

        When rows have been assigned to this table instance before calling this method, these rows will be reassigned to the body to prevent creating an invalid dom structure.

        Any subsequent calls to this table's addRows(TableRow...) method will be delegated to the body's one.
        Returns:
        table body
      • getFoot

        public TableFoot getFoot()
        Returns the TableFoot for this instance. Creates a new instance on the first call.
        Returns:
        foot
      • addRows

        public void addRows​(TableRow... rows)
        Adds the given list of rows.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        addRows in interface TableRowContainer
        Parameters:
        rows - rows
      • insertRows

        public void insertRows​(int index,
                               TableRow... rows)
        Inserts the given rows at the given index to this instance. Existing items will be placed after the inserted items.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        insertRows in interface TableRowContainer
        Parameters:
        rows - rows
        index - to insert the rows at
      • replaceRow

        public void replaceRow​(int index,
                               TableRow row)
        Replaces a single row instance to the given index in this container and replaces the existing row.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        replaceRow in interface TableRowContainer
        Parameters:
        index - index to set the new item to
        row - row
      • removeRows

        public void removeRows​(TableRow... rows)
        Removes the given rows from this instance. Items, that are not child of this instance, will lead to an exception.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        removeRows in interface TableRowContainer
        Parameters:
        rows - rows to remove
      • streamRows

        public Stream<TableRow> streamRows()
        Returns the rows of this instance as a stream. Empty if no rows have been added yet.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        streamRows in interface TableRowContainer
        Returns:
        rows as stream
      • addRow

        public TableRow addRow()
        Adds a single row instance to this container. The created row is returned for further configuration.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        addRow in interface TableRowContainer
        Returns:
        the created row
      • addRows

        public TableRow[] addRows​(int rows)
        Adds multiple rows to this instance based on the given integer (must be greater than 0). The created rows are returned as an array, that can be used for further configuration.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        addRows in interface TableRowContainer
        Parameters:
        rows - amount of rows to add
        Returns:
        created row objects
      • insertRow

        public TableRow insertRow​(int index)
        Inserts a single row instance at the given index to this container. Existing items will be placed after the inserted items. The created row is returned for further configuration.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        insertRow in interface TableRowContainer
        Parameters:
        index - to insert the row at
        Returns:
        the created row
      • setRow

        public void setRow​(int index,
                           TableRow row)
        Replaces a single row instance to the given index in this container and replaces the existing row.

        This method has the same functionality as replaceRow(int, TableRow).

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        setRow in interface TableRowContainer
        Parameters:
        index - index to set the new item to
        row - row
        See Also:
        replaceRow(int, TableRow)
      • removeAllRows

        public void removeAllRows()
        Removes all rows.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        removeAllRows in interface TableRowContainer
      • removeRow

        public void removeRow​(int index)
        Removes the row with the given index. Noop, if no row has been found for that index.

        When this table has a body, it will automatically delegate the call to the body's respective method.
        Specified by:
        removeRow in interface TableRowContainer
        Parameters:
        index - index to remove