Class Grid.Column<T>

    • Field Detail

      • grid

        protected final Grid<?> grid
      • headerTemplate

        protected Element headerTemplate
      • footerTemplate

        protected Element footerTemplate
    • Constructor Detail

      • Column

        public Column​(Grid<T> grid,
                      String columnId,
                      Renderer<T> renderer)
        Constructs a new Column for use inside a Grid.
        Parameters:
        grid - the grid this column is attached to
        columnId - unique identifier of this column
        renderer - the renderer to use in this column, must not be null
    • Method Detail

      • destroyDataGenerators

        protected void destroyDataGenerators()
      • getInternalId

        protected String getInternalId()
      • getRenderer

        public Renderer<T> getRenderer()
        Get the renderer used for this column.

        Note: Mutating the renderer after the Grid has been rendered on the client will not change the column, and can lead to undefined behavior.

        Returns:
        the renderer used for this column, should never be null
      • setWidth

        public Grid.Column<T> setWidth​(String width)
        Sets the width of this column as a CSS-string.
        Parameters:
        width - the width to set this column to, as a CSS-string, not null
        Returns:
        this column, for method chaining
        See Also:
        setFlexGrow(int)
      • setFlexGrow

        public Grid.Column<T> setFlexGrow​(int flexGrow)
        Sets the flex grow ratio for this column. When set to 0, column width is fixed.
        Parameters:
        flexGrow - the flex grow ratio
        Returns:
        this column, for method chaining
        See Also:
        setWidth(String)
      • setAutoWidth

        public Grid.Column<T> setAutoWidth​(boolean autoWidth)
        Enables or disables automatic width for this column.

        Automatically sets the width of the column based on the column contents when this is set to true.

        For performance reasons the column width is calculated automatically only once when the grid items are rendered for the first time and the calculation only considers the rows which are currently rendered in DOM (a bit more than what is currently visible). If the grid is scrolled, or the cell content changes, the column width might not match the contents anymore.

        Hidden columns are ignored in the calculation and their widths are not automatically updated when you show a column that was initially hidden.

        You can manually trigger the auto sizing behavior again by calling Grid.recalculateColumnWidths().

        The column width may still grow larger when flexGrow is not 0.

        Parameters:
        autoWidth - whether to enable or disable automatic width on this column
        Returns:
        this column, for method chaining
        See Also:
        Grid.recalculateColumnWidths(), setFlexGrow(int)
      • isAutoWidth

        public boolean isAutoWidth()
        Gets this column's auto width state.
        Returns:
        whether this column has automatic width enabled
      • getKey

        public String getKey()
        Gets the user-defined key for this column, or null if no key has been set.
        Returns:
        the user-defined key
      • getElement

        public Element getElement()
        Gets the underlying <vaadin-grid-column> element.

        It is highly discouraged to directly use the API exposed by the returned element.

        Specified by:
        getElement in interface HasElement
        Overrides:
        getElement in class Component
        Returns:
        the root element of this component
      • setComparator

        public Grid.Column<T> setComparator​(Comparator<T> comparator)
        Sets a comparator to use with in-memory sorting with this column. Sorting with a back-end is done using setSortProperty(String...).

        Note: calling this method automatically sets the column as sortable with setSortable(boolean).

        Note: Comparator is not serializable. If you need to write serializable implementation, use inlined class of SerializableComparator instead of Lambda expression.

        Parameters:
        comparator - the comparator to use when sorting data in this column
        Returns:
        this column
      • getComparator

        public SerializableComparator<T> getComparator​(SortDirection sortDirection)
        Gets the comparator to use with in-memory sorting for this column when sorting in the given direction.

        Note: calling this method automatically sets the column as sortable with setSortable(boolean).

        Parameters:
        sortDirection - the direction this column is sorted by
        Returns:
        comparator for this column
      • setSortProperty

        public Grid.Column<T> setSortProperty​(String... properties)
        Sets strings describing back end properties to be used when sorting this column.

        Note: calling this method automatically sets the column as sortable with setSortable(boolean).

        Parameters:
        properties - the array of strings describing backend properties
        Returns:
        this column
      • setSortOrderProvider

        public Grid.Column<T> setSortOrderProvider​(SortOrderProvider provider)
        Sets the sort orders when sorting this column. The sort order provider is a function which provides QuerySortOrder objects to describe how to sort by this column.

        The default provider uses the sort properties set with setSortProperty(String...).

        Note: calling this method automatically sets the column as sortable with setSortable(boolean).

        Parameters:
        provider - the function to use when generating sort orders with the given direction
        Returns:
        this column
      • setSortable

        public Grid.Column<T> setSortable​(boolean sortable)
        Sets whether the user can sort this column or not.
        Parameters:
        sortable - true if the column can be sorted by the user; false if not
        Returns:
        this column
      • isSortable

        public boolean isSortable()
        Gets whether this column is sortable (e.g. shows the sorting indicators at the client-side).
        Returns:
        true if the column is sortable, false otherwise
      • setHeader

        public Grid.Column<T> setHeader​(String labelText)
        Sets a header text to the column.

        If there are no header rows when calling this method, the first header row will be created. If there are header rows, the header will be set on the first created header row and it will override any existing header.

        Parameters:
        labelText - the text to be shown at the column header
        Returns:
        this column, for method chaining
      • setFooter

        public Grid.Column<T> setFooter​(String labelText)
        Sets a footer text to the column.

        If there are no footer rows when calling this method, the first footer row will be created. If there are footer rows, the footer will be set on the bottom footer row and it will override any existing footer.

        Parameters:
        labelText - the text to be shown at the column footer
        Returns:
        this column, for method chaining
      • setHeader

        public Grid.Column<T> setHeader​(Component headerComponent)
        Sets a header component to the column.

        If there are no header rows when calling this method, the first header row will be created. If there are header rows, the header will be set on the first created header row and it will override any existing header.

        Parameters:
        headerComponent - the component to be used in the header of the column
        Returns:
        this column, for method chaining
      • setFooter

        public Grid.Column<T> setFooter​(Component footerComponent)
        Sets a footer component to the column.

        If there are no footer rows when calling this method, the first footer row will be created. If there are footer rows, the footer will be set on the bottom footer row and it will override any existing footer.

        Parameters:
        footerComponent - the component to be used in the footer of the column
        Returns:
        this column, for method chaining
      • setClassNameGenerator

        public Grid.Column<T> setClassNameGenerator​(SerializableFunction<T,​String> classNameGenerator)
        Sets the function that is used for generating CSS class names for cells in this column. Returning null from the generator results in no custom class name being set. Multiple class names can be returned from the generator as space-separated.

        If Grid.setClassNameGenerator(SerializableFunction) is used together with this method, resulting class names from both methods will be effective. Class names generated by grid are applied to the cells before the class names generated by column. This means that if the classes contain conflicting style properties, column's classes will win.

        Parameters:
        classNameGenerator - the class name generator to set, not null
        Returns:
        this column
        Throws:
        NullPointerException - if classNameGenerator is null
        See Also:
        Grid.setClassNameGenerator(SerializableFunction)
      • getClassNameGenerator

        public SerializableFunction<T,​String> getClassNameGenerator()
        Gets the function that is used for generating CSS class names for cells in this column.
        Returns:
        the class name generator
      • getBottomLevelColumn

        protected Grid.Column<?> getBottomLevelColumn()
        Gets the <vaadin-grid-column> component that is a child of this component, or this component in case this is a bottom level <vaadin-grid-column> component. This method should be called only on components which have only one such bottom-level column (not on ColumnGroups with multiple children).
        Returns:
        the bottom column component
      • getGrid

        public Grid<?> getGrid()
        Gets the owner of this column.
        Returns:
        the grid which owns this column
      • setVisible

        public void setVisible​(boolean visible)
        Sets the component visibility value.

        When a component is set as invisible, all the updates of the component from the server to the client are blocked until the component is set as visible again.

        Invisible components don't receive any updates from the client-side. Unlike the server-side updates, client-side updates, if any, are discarded while the component is invisible, and are not transmitted to the server when the component is made visible.

        Note that column related data is sent to the client side even if the column is invisible. Use Grid.removeColumn(Column) to remove column (or don't add the column all) and avoid sending extra data.

        Overrides:
        setVisible in class Component
        Parameters:
        visible - the component visibility value
        See Also:
        Grid.removeColumn(Column)
      • setHeaderRenderer

        protected void setHeaderRenderer​(Renderer<?> renderer)
      • setFooterRenderer

        protected void setFooterRenderer​(Renderer<?> renderer)
      • setHeaderText

        protected void setHeaderText​(String text)
      • setFooterText

        protected void setFooterText​(String text)
      • setHeaderComponent

        protected void setHeaderComponent​(Component component)
      • setFooterComponent

        protected void setFooterComponent​(Component component)
      • getHeaderRenderer

        protected Renderer<?> getHeaderRenderer()
      • getFooterRenderer

        protected Renderer<?> getFooterRenderer()
      • updateSortingIndicators

        protected void updateSortingIndicators​(boolean sortable)
        Updates this component to either have sorting indicators according to the sortable state of the underlying column, or removes the sorting indicators.
        Parameters:
        sortable - true to have sorting indicators if the column is sortable, false to not have sorting indicators
      • setSortingIndicators

        protected void setSortingIndicators​(boolean sortingIndicators)
        Sets this component to show sorting indicators or not.
        Parameters:
        sortingIndicators - true to show sorting indicators, false to remove them
      • hasSortingIndicators

        protected boolean hasSortingIndicators()
      • setBaseHeaderTemplate

        protected void setBaseHeaderTemplate​(String headerTemplate)
      • addGridSorter

        protected String addGridSorter​(String templateInnerHtml)
      • getBottomChildColumns

        protected List<Grid.Column<?>> getBottomChildColumns()
        Gets recursively the child components of this component that are instances of Column.
        Returns:
        the Column children of this component
      • setResizable

        public default T setResizable​(boolean resizable)
        When set to true, the column is user-resizable. By default this is set to false.
        Parameters:
        resizable - whether to allow user resizing of this column
        Returns:
        this column, for method chaining
      • isResizable

        @Synchronize("resizable-changed")
        public default boolean isResizable()
        Gets whether this column is user-resizable.
        Returns:
        whether this column is user-resizable
      • setFrozen

        public default T setFrozen​(boolean frozen)
        Sets this column's frozen state.

        Note: Columns are frozen in-place, freeze columns from left to right for a consistent outcome.

        Parameters:
        frozen - whether to freeze or unfreeze this column
        Returns:
        this column, for method chaining
      • isFrozen

        @Synchronize("frozen-changed")
        public default boolean isFrozen()
        Gets the this column's frozen state.
        Returns:
        whether this column is frozen
      • setTextAlign

        public default T setTextAlign​(ColumnTextAlign textAlign)
        Sets the column text align.
        Parameters:
        textAlign - the text alignment of the column. Setting it to null resets the alignment to the default value ColumnTextAlign.START.
        Returns:
        this column, for method chaining