Class Table

All Implemented Interfaces:
Buffered, BufferedValidatable, Container, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Viewer, Property<Object>, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Field<Object>, Select, Validatable, ClientConnector, FAbstractClientConnector, FSizeable, Sizeable, ComponentContainer, FAbstractComponent, HasComponents, HasComponents.ComponentAttachDetachNotifier, com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasValue, com.vaadin.flow.component.shared.HasTooltip, Serializable, Iterable<com.vaadin.flow.component.Component>

@Tag("div") @CssImport("@vaadin/vaadin-lumo-styles/lumo.css") public class Table extends AbstractComponentContainer implements Select, com.vaadin.flow.component.HasValue
A Flow component for v7 Table with api compatibility internally using the Grid component.
See Also:
  • Constructor Details

    • Table

      public Table()
    • Table

      public Table(String captionText)
  • Method Details

    • setLabelComponent

      public void setLabelComponent(com.vaadin.flow.component.Component labelComponent)
      Description copied from interface: FAbstractComponent
      Sets the component's label component. Flow components that support caption component usually overrides this.
      Specified by:
      setLabelComponent in interface FAbstractComponent
      Parameters:
      labelComponent - the new label component for the component.
    • setContainerDataSource

      public void setContainerDataSource(Container newDataSource)
      Description copied from interface: Container.Viewer
      Sets the Container that serves as the data source of the viewer.
      Specified by:
      setContainerDataSource in interface Container.Viewer
      Specified by:
      setContainerDataSource in interface Select
      Parameters:
      newDataSource - The new data source Item
    • setContainerDataSource

      public void setContainerDataSource(Container newDataSource, Collection<?> visibleIds)
      Sets the container data source and the columns that will be visible. Columns are shown in the collection's iteration order.

      Keeps propertyValueConverters if the corresponding id exists in the new data source and is of a compatible type.

      Parameters:
      newDataSource - the new data source.
      visibleIds - IDs of the visible columns
      See Also:
    • setColumnWidth

      public void setColumnWidth(Object propertyId, int width)
    • getColumnWidth

      public int getColumnWidth(Object propertyId)
      Gets the pixel width of column
      Parameters:
      propertyId -
      Returns:
      width of column or -1 when value not set
    • setCellStyleGenerator

      public void setCellStyleGenerator(Table.CellStyleGenerator cellStyleGenerator)
      Sets the function that is used for generating CSS part names for cells in this column. Returning null from the generator results in no custom part name being set. Multiple part names can be returned from the generator as space-separated.

      If setPartNameGenerator(SerializableFunction) is used together with this method, resulting part names from both methods will be effective.

      Parameters:
      cellStyleGenerator - the part name generator to set, not null
      Throws:
      NullPointerException - if cellStyleGenerator is null
      See Also:
    • setPartNameGenerator

      public void setPartNameGenerator(com.vaadin.flow.function.SerializableFunction<Item,String> partNameGenerator)
      Sets the function that is used for generating CSS part names for all the cells in the rows in this grid. Returning null from the generator results in no custom part name being set. Multiple part names can be returned from the generator as space-separated.

      If setCellStyleGenerator(com.vaadin.featurepack.ui.Table.CellStyleGenerator) is used together with this method, resulting part names from both methods will be effective.

      Parameters:
      partNameGenerator - the part name generator to set, not null
      Throws:
      NullPointerException - if partNameGenerator is null
      See Also:
      • Grid.Column.setPartNameGenerator(SerializableFunction)
    • setItemDescriptionGenerator

      public void setItemDescriptionGenerator(ItemDescriptionGenerator generator)
      Set the item description generator which generates tooltips for cells and rows in the Table
      Parameters:
      generator - The generator to use or null to disable
    • setTooltipPosition

      public void setTooltipPosition(com.vaadin.flow.component.shared.Tooltip.TooltipPosition position)
      Position of the cell tooltip with respect to the cell.
      Parameters:
      position - the position to set
    • setSelectable

      public void setSelectable(boolean selectable)
    • isSelectable

      public boolean isSelectable()
    • setPageLength

      public void setPageLength(int pageLength)
    • getPageLength

      public int getPageLength()
    • isSortEnabled

      public boolean isSortEnabled()
    • setSortEnabled

      public void setSortEnabled(boolean sortEnabled)
      Enables or disables sorting.

      Setting this to false disallows sorting by the user.

      Parameters:
      sortEnabled - true to allow the user to sort the table, false to disallow it
    • sort

      public void sort()
      Sorts the table by currently selected sorting column.
      Throws:
      UnsupportedOperationException - if the container data source does not implement Container.Sortable
    • sort

      public void sort(Object[] propertyId, boolean[] ascending)
      Sorts the table.
    • isSortAscending

      public boolean isSortAscending()
      Is the table currently sorted in ascending order.
      Returns:
      true if ascending, false if descending.
    • setSortAscending

      public void setSortAscending(boolean ascending)
      Sets the table in ascending order.
      Parameters:
      ascending - true if ascending, false if descending.
    • getSortContainerPropertyId

      public Object getSortContainerPropertyId()
      Gets the currently sorted column property ID.
      Returns:
      the Container property id of the currently sorted column.
    • setSortContainerPropertyId

      public void setSortContainerPropertyId(Object propertyId)
      Sets the currently sorted column property id.
      Parameters:
      propertyId - the Container property id of the currently sorted column.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Field
      Is the field empty? In general, "empty" state is same as null. As an exception, TextField also treats empty string as "empty".
      Specified by:
      isEmpty in interface Field<Object>
      Specified by:
      isEmpty in interface com.vaadin.flow.component.HasValue
      Returns:
      true if the field is empty, false otherwise
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValue
    • isReadOnly

      public boolean isReadOnly()
      Specified by:
      isReadOnly in interface com.vaadin.flow.component.HasValue
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean visible)
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue
    • isRequiredIndicatorVisible

      public boolean isRequiredIndicatorVisible()
      Specified by:
      isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue
    • setColumnReorderingAllowed

      public void setColumnReorderingAllowed(boolean columnReorderingAllowed)
    • isColumnReorderingAllowed

      public boolean isColumnReorderingAllowed()
    • getColumnHeaders

      public String[] getColumnHeaders()
      Gets the headers of the columns.
      Returns:
      the Array of column headers.
    • setColumnHeaders

      public void setColumnHeaders(String... columnHeaders)
      Sets the headers of the columns.
      Parameters:
      columnHeaders - the Array of column headers that match the getVisibleColumns() method.
    • getColumnHeader

      public String getColumnHeader(Object propertyId)
      Gets the header for the specified column.
      Parameters:
      propertyId - the propertyId identifying the column.
      Returns:
      the header for the specified column if it has one.
    • getValue

      public Object getValue()
      Gets the selected item id or in multiselect mode a set of selected ids.
      Specified by:
      getValue in interface com.vaadin.flow.component.HasValue
      Specified by:
      getValue in interface Property<Object>
      Specified by:
      getValue in interface Select
      Returns:
      the value stored in the Property
    • setHeight

      public void setHeight(String height)
      Description copied from interface: Sizeable
      Sets the height of the component using String presentation.

      String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size.

      The empty string ("") or null will unset the height and set the units to pixels.

      See CSS specification for more details.

      Specified by:
      setHeight in interface FSizeable
      Specified by:
      setHeight in interface Sizeable
      Overrides:
      setHeight in class AbstractComponent
      Parameters:
      height - in CSS style string representation
    • setHeight

      public void setHeight(float height, com.vaadin.flow.component.Unit unit)
      Description copied from interface: Sizeable
      Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      setHeight in interface FSizeable
      Specified by:
      setHeight in interface Sizeable
      Overrides:
      setHeight in class AbstractComponentContainer
      Parameters:
      height - the height of the object.
      unit - the unit used for the width.
    • addValueChangeListener

      public com.vaadin.flow.shared.Registration addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener valueChangeListener)
      Specified by:
      addValueChangeListener in interface com.vaadin.flow.component.HasValue
    • setValue

      public void setValue(Object value)
      Description copied from interface: Property
      Sets the value of the Property.

      Implementing this functionality is optional. If the functionality is missing, one should declare the Property to be in read-only mode and throw Property.ReadOnlyException in this function.

      Note : Since Vaadin 7.0, setting the value of a non-String property as a String is no longer supported.
      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue
      Specified by:
      setValue in interface Property<Object>
      Specified by:
      setValue in interface Select
      Parameters:
      value - New value of the Property. This should be assignable to the type returned by getType
    • setMultiSelect

      public void setMultiSelect(boolean multiSelect)
      Specified by:
      setMultiSelect in interface Select
    • isColumnCollapsed

      public boolean isColumnCollapsed(Object propertyId)
    • setColumnCollapsible

      public void setColumnCollapsible(Object propertyId, boolean collapsible)
      Sets whether the given column is collapsible. Note that collapsible columns can only be actually collapsed (via UI or with setColumnCollapsed()) if isColumnCollapsingAllowed() is true. By default, all columns are collapsible.
      Parameters:
      propertyId - the propertyID identifying the column.
      collapsible - true if the column should be collapsible, false otherwise.
    • isColumnCollapsible

      public boolean isColumnCollapsible(Object propertyId)
      Checks if the given column is collapsible. Note that even if this method returns true, the column can only be actually collapsed (via UI or with setColumnCollapsed()) if isColumnCollapsingAllowed() is also true.
      Returns:
      true if the column can be collapsed; false otherwise.
    • setColumnCollapsed

      public void setColumnCollapsed(Object propertyId, boolean collapsed) throws IllegalStateException
      Sets whether the specified column is collapsed or not.
      Parameters:
      propertyId - the propertyID identifying the column.
      collapsed - the desired collapsedness.
      Throws:
      IllegalStateException - if column collapsing is not allowed
      IllegalArgumentException - if the property id does not exist
    • isColumnCollapsingAllowed

      public boolean isColumnCollapsingAllowed()
      Checks if column collapsing is allowed.
      Returns:
      true if columns can be collapsed; false otherwise.
    • setColumnCollapsingAllowed

      public void setColumnCollapsingAllowed(boolean columnCollapsingAllowed)
      Sets whether column collapsing is allowed or not.
      Parameters:
      columnCollapsingAllowed - specifies whether column collapsing is allowed.
    • getType

      public Class<?> getType()
      Description copied from interface: Property
      Returns the type of the Property. The methods getValue and setValue must be compatible with this type: one must be able to safely cast the value returned from getValue to the given type and pass any variable assignable to this type as an argument to setValue.
      Specified by:
      getType in interface Field<Object>
      Specified by:
      getType in interface Property<Object>
      Returns:
      type of the Property
    • getVisibleColumns

      public Object[] getVisibleColumns()
    • setVisibleColumns

      public void setVisibleColumns(Object... visibleColumns)
      Sets the array of visible column property id:s.

      The columns are shown in the order of their appearance in this array.

      Parameters:
      visibleColumns - the Array of shown property id:s.
    • setConverter

      public <PROPERTY_TYPE> void setConverter(Object propertyId, com.vaadin.flow.data.converter.Converter<String,PROPERTY_TYPE> converter)
      Sets a converter for a property id.

      The converter is used to format the data for the given property id before displaying it in the table.

      Parameters:
      propertyId - The propertyId to format using the converter
      converter - The converter to use for the property id
    • hasConverter

      protected boolean hasConverter(Object propertyId)
      Checks if there is a converter set explicitly for the given property id.
      Parameters:
      propertyId - The propertyId to check
      Returns:
      true if a converter has been set for the property id, false otherwise
    • getConverter

      public com.vaadin.flow.data.converter.Converter<String,Object> getConverter(Object propertyId)
      Returns the converter used to format the given propertyId.
      Parameters:
      propertyId - The propertyId to check
      Returns:
      The converter used to format the propertyId or null if no converter has been set
    • getType

      public Class<?> getType(Object propertyId)
      Description copied from interface: Container
      Gets the data type of all Properties identified by the given Property ID.
      Specified by:
      getType in interface Container
      Specified by:
      getType in interface Select
      Parameters:
      propertyId - ID identifying the Properties
      Returns:
      data type of the Properties
    • addContainerProperty

      public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue)
      Description copied from interface: Container
      Adds a new Property to all Items in the Container. The Property ID, data type and default value of the new Property are given as parameters.

      This functionality is optional.

      Specified by:
      addContainerProperty in interface Container
      Specified by:
      addContainerProperty in interface Select
      Parameters:
      propertyId - ID of the Property
      type - Data type of the new Property
      defaultValue - The value all created Properties are initialized to
      Returns:
      true if the operation succeeded, false if not
    • removeContainerProperty

      public boolean removeContainerProperty(Object propertyId)
      Description copied from interface: Container
      Removes a Property specified by the given Property ID from the Container. Note that the Property will be removed from all Items in the Container.

      This functionality is optional.

      Specified by:
      removeContainerProperty in interface Container
      Specified by:
      removeContainerProperty in interface Select
      Parameters:
      propertyId - ID of the Property to remove
      Returns:
      true if the operation succeeded, false if not
    • addItem

      public Object addItem(Object[] cells, Object itemId) throws UnsupportedOperationException
      Adds the new row to table and fill the visible cells (except generated columns) with given values.
      Parameters:
      cells - the Object array that is used for filling the visible cells new row. The types must be settable to visible column property types.
      itemId - the Id the new row. If null, a new id is automatically assigned. If given, the table cannot already have a item with given id.
      Returns:
      Returns item id for the new row. Returns null if operation fails.
      Throws:
      UnsupportedOperationException
    • replaceComponent

      public void replaceComponent(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent)
      Description copied from interface: ComponentContainer
      Replaces the component in the container with another one without changing position.

      This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.

      Specified by:
      replaceComponent in interface ComponentContainer
      Parameters:
      oldComponent - the old component that will be replaced.
      newComponent - the new component to be replaced.
    • getComponentCount

      public int getComponentCount()
      Description copied from interface: ComponentContainer
      Gets the number of children this ComponentContainer has
      Specified by:
      getComponentCount in interface ComponentContainer
      Specified by:
      getComponentCount in interface com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>
      Returns:
      The number of child components this container has.
    • getContainerPropertyIds

      public Collection<?> getContainerPropertyIds()
      Description copied from interface: Container
      Gets the ID's of all Properties stored in the Container. The ID's cannot be modified through the returned collection.
      Specified by:
      getContainerPropertyIds in interface Container
      Specified by:
      getContainerPropertyIds in interface Select
      Returns:
      unmodifiable collection of Property IDs
    • addColumnReorderListener

      public void addColumnReorderListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.ColumnReorderEvent<Item>> listener)
    • addColumnResizeListener

      public void addColumnResizeListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.ColumnResizeEvent<Item>> listener)
    • addItemClickListener

      public void addItemClickListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.ItemClickEvent<Item>> listener)
    • valueChange

      public void valueChange(Property.ValueChangeEvent arg0)
      Description copied from interface: Property.ValueChangeListener
      Notifies this listener that the Property's value has changed.
      Specified by:
      valueChange in interface Field<Object>
      Specified by:
      valueChange in interface Property.ValueChangeListener
      Parameters:
      arg0 - value change event object
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class AbstractClientConnector
    • onDetach

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class AbstractClientConnector