Class TableColumnGroup

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.HtmlComponent
com.vaadin.flow.component.html.TableColumnGroup
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponentsOfType<TableColumn>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, TableColumnSpan, Serializable

@NullMarked @Tag("colgroup") public class TableColumnGroup extends com.vaadin.flow.component.HtmlComponent implements TableColumnSpan, com.vaadin.flow.component.HasComponentsOfType<TableColumn>
Component representing a <colgroup> element — a group of columns inside a Table, used to apply attributes (most often a class for CSS) to several columns at once. Only a limited subset of CSS applies to column groups: background, border (with border-collapse: collapse), visibility: collapse and width.

Per the WHATWG HTML specification, a <colgroup> is used in one of two modes: either it carries a span attribute and has no children, or it contains zero or more <col> children and has no span attribute. This component enforces that: adding a column to a group that carries a span throws, as does setting a span on a group that already has columns. Call TableColumnSpan.resetSpan() or HasComponentsOfType.removeAll() first to switch a group from one mode to the other. <colgroup> elements must be placed after the optional <caption> and before any <thead>, <tbody>, <tfoot> or <tr>; Table inserts them at the correct position automatically.

Since:
25.3
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty column group.
    Creates a new column group with the given columns appended.
    TableColumnGroup(List<? extends TableColumn> columns)
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    Appends a new empty <col> child to this group.
    addColumn(int span)
    Appends a new <col> child with the given span to this group.
    void
     
    void
    addComponentAtIndex(int index, TableColumn column)
     
    <V extends @Nullable Object, S extends com.vaadin.flow.signals.Signal<V>>
    void
    bindChildren(com.vaadin.flow.signals.Signal<List<S>> list, com.vaadin.flow.function.SerializableFunction<S,TableColumn> childFactory)
    Not supported.
    Returns the columns inside this group.
    insertColumn(int position)
    Creates a new empty <col> and inserts it at the given position in this group.
    void
    replace(TableColumn oldColumn, TableColumn newColumn)
     
    void
    setSpan(int span)
    Sets the span attribute — how many consecutive columns this element covers.

    Methods inherited from class com.vaadin.flow.component.HtmlComponent

    getTitle, setTitle

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, bindVisible, findAncestor, 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, whenAttached

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    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.HasComponentsOfType

    add, getChildren, getComponentAt, getComponentCount, indexOf, remove, remove, removeAll

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

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    bindEnabled, isEnabled, setEnabled

    Methods 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, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.html.TableColumnSpan

    getSpan, hasSpan, resetSpan
  • Constructor Details

    • TableColumnGroup

      public TableColumnGroup()
      Creates a new empty column group.
    • TableColumnGroup

      public TableColumnGroup(TableColumn... columns)
      Creates a new column group with the given columns appended.
      Parameters:
      columns - the columns to add.
    • TableColumnGroup

      public TableColumnGroup(List<? extends TableColumn> columns)
      Parameters:
      columns - the columns to add.
  • Method Details

    • addColumn

      public TableColumn addColumn()
      Appends a new empty <col> child to this group.
      Returns:
      the new column.
    • addColumn

      public TableColumn addColumn(int span)
      Appends a new <col> child with the given span to this group.
      Parameters:
      span - the number of columns to span.
      Returns:
      the new column.
    • insertColumn

      public TableColumn insertColumn(int position)
      Creates a new empty <col> and inserts it at the given position in this group. This is the counterpart of addColumn(), matching insertRow, insertHeaderCell and insertDataCell elsewhere in the family.
      Parameters:
      position - the position to insert the column at, between 0 and the number of columns in this group.
      Returns:
      the new column.
      Throws:
      IllegalStateException - if this group carries a span, which a <colgroup> may not do alongside <col> children. Call TableColumnSpan.resetSpan() first.
    • getColumns

      public List<TableColumn> getColumns()
      Returns the columns inside this group.
      Returns:
      the list of <col> children.
    • add

      public void add(Collection<TableColumn> columns)
      Specified by:
      add in interface com.vaadin.flow.component.HasComponentsOfType<TableColumn>
    • addComponentAtIndex

      public void addComponentAtIndex(int index, TableColumn column)
      Specified by:
      addComponentAtIndex in interface com.vaadin.flow.component.HasComponentsOfType<TableColumn>
    • addComponentAsFirst

      public void addComponentAsFirst(TableColumn column)
      Specified by:
      addComponentAsFirst in interface com.vaadin.flow.component.HasComponentsOfType<TableColumn>
    • replace

      public void replace(TableColumn oldColumn, TableColumn newColumn)
      Specified by:
      replace in interface com.vaadin.flow.component.HasComponentsOfType<TableColumn>
    • bindChildren

      public <V extends @Nullable Object, S extends com.vaadin.flow.signals.Signal<V>> void bindChildren(com.vaadin.flow.signals.Signal<List<S>> list, com.vaadin.flow.function.SerializableFunction<S,TableColumn> childFactory)
      Not supported. The columns of a <colgroup> are structure rather than data, and a binding would attach them straight to the element, bypassing the check that keeps span and <col> children mutually exclusive. Bind the rows of a TableBody instead.
      Specified by:
      bindChildren in interface com.vaadin.flow.component.HasComponentsOfType<TableColumn>
      Throws:
      UnsupportedOperationException - always.
    • setSpan

      public void setSpan(int span)
      Sets the span attribute — how many consecutive columns this element covers. The default is 1. Use it to apply the same styling or attributes across a range of columns without writing one element per column.

      A <colgroup> carrying a span may not also have <col> children, so this refuses a group that already has some.

      Specified by:
      setSpan in interface TableColumnSpan
      Parameters:
      span - a positive integer.
      Throws:
      IllegalStateException - if this group has <col> children. Call HasComponentsOfType.removeAll() first.