com.vaadin.ui.

Class Grid.Column<T,​V>

    • Constructor Detail

      • Column

        protected Column​(ValueProvider<T,​V> valueProvider,
                         Renderer<? super V> renderer)

        Constructs a new Column configuration with given renderer and value provider.

        Parameters:

        valueProvider - the function to get values from items, not null

        renderer - the value renderer, not null

      • Column

        protected Column​(ValueProvider<T,​V> valueProvider,
                         ValueProvider<V,​P> presentationProvider,
                         Renderer<? super P> renderer)

        Constructs a new Column configuration with given renderer and value provider.

        For a more complete explanation on presentation provider, see setRenderer(ValueProvider, Renderer).

        Type Parameters:

        P - the presentation type

        Parameters:

        valueProvider - the function to get values from items, not null

        presentationProvider - the function to get presentations from the value of this column, not null. For more details, see setRenderer(ValueProvider, Renderer)

        renderer - the presentation renderer, not null

        Since:

        8.1

      • Column

        protected Column​(ValueProvider<T,​V> valueProvider,
                         ValueProvider<V,​P> presentationProvider,
                         Renderer<? super P> renderer,
                         Grid.Column.NestedNullBehavior nestedNullBehavior)

        Constructs a new Column configuration with given renderer and value provider.

        For a more complete explanation on presentation provider, see setRenderer(ValueProvider, Renderer).

        Type Parameters:

        P - the presentation type

        Parameters:

        valueProvider - the function to get values from items, not null

        presentationProvider - the function to get presentations from the value of this column, not null. For more details, see setRenderer(ValueProvider, Renderer)

        nestedNullBehavior - behavior on encountering nested null values when reading the value from the bean

        renderer - the presentation renderer, not null

        Since:

        8.8

    • Method Detail

      • getState

        protected ColumnState getState()

        Description copied from class: AbstractClientConnector

        Returns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.

        As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use getState(false) to avoid marking the connector as dirty.

        Overrides:

        getState in class AbstractClientConnector

        Returns:

        The shared state for this connector. Never null.

      • getId

        public String getId()

        Returns the user-defined identifier for this column.

        Returns:

        the identifier string

      • getValueProvider

        public ValueProvider<T,​V> getValueProvider()

        Gets the function used to produce the value for data in this column based on the row item.

        Returns:

        the value provider function

        Since:

        8.0.3

      • getPresentationProvider

        public ValueProvider<V,​?> getPresentationProvider()

        Gets the function to get presentations from the value of data in this column, based on the row item.

        Returns:

        the presentation provider function

        Since:

        8.13

      • setSortable

        public Grid.Column<T,​V> setSortable​(boolean sortable)

        Sets whether the user can sort this column or not. Whether the column is actually sortable after setSortable(true) depends on the DataProvider and the defined sort order for this column. When using an InMemoryDataProvider sorting can be automatic.

        Parameters:

        sortable - true to enable sorting for this column; false to disable it

        Returns:

        this column

      • isSortable

        public boolean isSortable()

        Gets whether sorting is enabled for this column.

        Returns:

        true if the sorting is enabled for this column; false if not

      • isSortableByUser

        public boolean isSortableByUser()

        Gets whether the user can actually sort this column.

        Returns:

        true if the column can be sorted by the user; false if not

        Since:

        8.3.2

      • setAssistiveCaption

        public Grid.Column<T,​V> setAssistiveCaption​(String caption)

        Sets the header aria-label for this column.

        Parameters:

        caption - the header aria-label, null removes the aria-label from this column

        Returns:

        this column

        Since:

        8.2

      • getAssistiveCaption

        public String getAssistiveCaption()

        Gets the header caption for this column.

        Returns:

        header caption

        Since:

        8.2

      • setCaption

        public Grid.Column<T,​V> setCaption​(String caption)

        Sets the header caption for this column.

        Parameters:

        caption - the header caption, not null

        Returns:

        this column

      • getCaption

        public String getCaption()

        Gets the header caption for this column.

        Returns:

        header caption

      • setComparator

        public Grid.Column<T,​V> setComparator​(SerializableComparator<T> comparator)

        Sets a comparator to use with in-memory sorting with this column. Sorting with a back-end is done using setSortProperty(String...).

        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.

        Parameters:

        sortDirection - the direction this column is sorted by

        Returns:

        comparator for this column

      • setSortProperty

        public Grid.Column<T,​V> setSortProperty​(String... properties)

        Sets strings describing back end properties to be used when sorting this column.

        By default, the column id will be used as the sort property.

        Parameters:

        properties - the array of strings describing backend properties

        Returns:

        this column

      • setSortOrderProvider

        public Grid.Column<T,​V> 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.

        By default, the column id will be used as the sort property.

        Parameters:

        provider - the function to use when generating sort orders with the given direction

        Returns:

        this column

      • setStyleGenerator

        public Grid.Column<T,​V> setStyleGenerator​(StyleGenerator<T> cellStyleGenerator)

        Sets the style generator that is used for generating class names for cells in this column. Returning null from the generator results in no custom style name being set. Note: The style generator is applied only to the body cells, not to the Editor.

        Parameters:

        cellStyleGenerator - the cell style generator to set, not null

        Returns:

        this column

        Throws:

        NullPointerException - if cellStyleGenerator is null

      • getStyleGenerator

        public StyleGenerator<T> getStyleGenerator()

        Gets the style generator that is used for generating styles for cells.

        Returns:

        the cell style generator

      • setDescriptionGenerator

        public Grid.Column<T,​V> setDescriptionGenerator​(DescriptionGenerator<T> cellDescriptionGenerator,
                                                              ContentMode tooltipContentMode)

        Sets the description generator that is used for generating descriptions for cells in this column. This method uses the given content mode.

        Parameters:

        cellDescriptionGenerator - the cell description generator to set, or null to remove a previously set generator

        tooltipContentMode - the content mode for tooltips

        Returns:

        this column

        Since:

        8.2

        See Also:

        setDescriptionGenerator(DescriptionGenerator)

      • getDescriptionGenerator

        public DescriptionGenerator<T> getDescriptionGenerator()

        Gets the description generator that is used for generating descriptions for cells.

        Returns:

        the cell description generator, or null if no generator is set

      • setExpandRatio

        public Grid.Column<T,​V> setExpandRatio​(int expandRatio)
                                              throws IllegalStateException

        Sets the ratio with which the column expands.

        By default, all columns expand equally (treated as if all of them had an expand ratio of 1). Once at least one column gets a defined expand ratio, the implicit expand ratio is removed, and only the defined expand ratios are taken into account.

        If a column has a defined width (setWidth(double)), it overrides this method's effects.

        Example: A grid with three columns, with expand ratios 0, 1 and 2, respectively. The column with a ratio of 0 is exactly as wide as its contents requires. The column with a ratio of 1 is as wide as it needs, plus a third of any excess space, because we have 3 parts total, and this column reserves only one of those. The column with a ratio of 2, is as wide as it needs to be, plus two thirds of the excess width.

        Parameters:

        expandRatio - the expand ratio of this column. 0 to not have it expand at all. A negative number to clear the expand value.

        Returns:

        this column

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

        See Also:

        setWidth(double)

      • getExpandRatio

        public int getExpandRatio()

        Returns the column's expand ratio.

        Returns:

        the column's expand ratio

        See Also:

        setExpandRatio(int)

      • getWidth

        public double getWidth()
                        throws IllegalStateException

        Returns the width (in pixels). By default a column width is -1.0 (undefined).

        Returns:

        the width in pixels of the column

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

      • isWidthUndefined

        public boolean isWidthUndefined()

        Returns whether this column has an undefined width.

        Returns:

        whether the width is undefined

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

        Since:

        7.6

      • setWidthUndefined

        public Grid.Column<T,​V> setWidthUndefined()

        Marks the column width as undefined. An undefined width means the grid is free to resize the column based on the cell contents and available space in the grid.

        Returns:

        the column itself

      • setMinimumWidth

        public Grid.Column<T,​V> setMinimumWidth​(double pixels)
                                               throws IllegalStateException

        Sets the minimum width for this column.

        This defines the minimum guaranteed pixel width of the column when it is set to expand. Note: Value -1 is not accepted, use setWidthUndefined() instead.

        Parameters:

        pixels - the minimum width for the column

        Returns:

        the column itself

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

        See Also:

        setExpandRatio(int)

      • getMinimumWidth

        public double getMinimumWidth()

        Return the minimum width for this column.

        Returns:

        the minimum width for this column

        See Also:

        setMinimumWidth(double)

      • setMinimumWidthFromContent

        public Grid.Column<T,​V> setMinimumWidthFromContent​(boolean minimumWidthFromContent)
                                                          throws IllegalStateException

        Sets whether the width of the contents in the column should be considered minimum width for this column.

        If this is set to true (default for backwards compatibility), then a column will not shrink to smaller than the width required to show the contents available when calculating the widths (only the widths of the initially rendered rows are considered).

        If this is set to false and the column has been set to expand using #setExpandRatio(int), then the contents of the column will be ignored when calculating the width, and the column will thus shrink down to the minimum width defined by #setMinimumWidth(double) if necessary.

        Parameters:

        minimumWidthFromContent - true to reserve space for all contents, false to allow the column to shrink smaller than the contents

        Returns:

        the column itself

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

        Since:

        8.1

        See Also:

        setMinimumWidth(double)

      • isMinimumWidthFromContent

        public boolean isMinimumWidthFromContent()

        Gets whether the width of the contents in the column should be considered minimum width for this column.

        Returns:

        true to reserve space for all contents, false to allow the column to shrink smaller than the contents

        Since:

        8.1

        See Also:

        setMinimumWidthFromContent(boolean)

      • setMaximumWidth

        public Grid.Column<T,​V> setMaximumWidth​(double pixels)

        Sets the maximum width for this column.

        This defines the maximum allowed pixel width of the column when it is set to expand.

        Parameters:

        pixels - the maximum width

        Returns:

        this column

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

        See Also:

        setExpandRatio(int)

      • getMaximumWidth

        public double getMaximumWidth()

        Returns the maximum width for this column.

        Returns:

        the maximum width for this column

        See Also:

        setMaximumWidth(double)

      • setResizable

        public Grid.Column<T,​V> setResizable​(boolean resizable)

        Sets whether this column can be resized by the user.

        Parameters:

        resizable - true if this column should be resizable, false otherwise

        Returns:

        this column

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

        Since:

        7.6

      • getHidingToggleCaption

        public String getHidingToggleCaption()

        Gets the caption of the hiding toggle for this column.

        Returns:

        the caption for the hiding toggle for this column

        Since:

        7.5.0

        See Also:

        setHidingToggleCaption(String)

      • setHidingToggleCaption

        public Grid.Column<T,​V> setHidingToggleCaption​(String hidingToggleCaption)

        Sets the caption of the hiding toggle for this column. Shown in the toggle for this column in the grid's sidebar when the column is hidable.

        The default value is null, and in that case the column's header caption is used.

        NOTE: setting this to empty string might cause the hiding toggle to not render correctly.

        Parameters:

        hidingToggleCaption - the text to show in the column hiding toggle

        Returns:

        the column itself

        Since:

        7.5.0

      • setHidden

        public Grid.Column<T,​V> setHidden​(boolean hidden)

        Hides or shows the column. By default columns are visible before explicitly hiding them.

        Parameters:

        hidden - true to hide the column, false to show

        Returns:

        this column

        Throws:

        IllegalStateException - if the column is no longer attached to any grid

        Since:

        7.5.0

      • isHidden

        public boolean isHidden()

        Returns whether this column is hidden. Default is false.

        Returns:

        true if the column is currently hidden, false otherwise

        Since:

        7.5.0

      • setHidable

        public Grid.Column<T,​V> setHidable​(boolean hidable)

        Sets whether this column can be hidden by the user. Hidable columns can be hidden and shown via the sidebar menu.

        Parameters:

        hidable - true if the column may be hidable by the user via UI interaction

        Returns:

        this column

        Since:

        7.5.0

      • isHidable

        public boolean isHidable()

        Returns whether this column can be hidden by the user. Default is false.

        Note: the column can be programmatically hidden using setHidden(boolean) regardless of the returned value.

        Returns:

        true if the user can hide the column, false if not

        Since:

        7.5.0

      • isResizable

        public boolean isResizable()

        Returns whether this column can be resized by the user. Default is true.

        Note: the column can be programmatically resized using setWidth(double) and setWidthUndefined() regardless of the returned value.

        Returns:

        true if this column is resizable, false otherwise

        Since:

        7.6

      • isEditable

        public boolean isEditable()

        Gets whether this Column has a component displayed in Editor or not.

        Returns:

        true if the column displays an editor component; false if not

      • getEditorBinding

        public Binder.Binding<T,​?> getEditorBinding()

        Gets the binder binding that is currently used for this column.

        Returns:

        the used binder binding, or null if no binding is configured

        See Also:

        setEditorBinding(Binding)

      • setEditorComponent

        public <F,​C extends HasValue<F> & ComponentGrid.Column<T,​V> setEditorComponent​(C editorComponent)

        Sets a component to use for editing values of this columns in the editor row. This method can only be used if the column has an id and the Grid has been created using Grid(Class) or some other way that allows finding properties based on property names.

        This is a shorthand for use in simple cases where no validator or converter is needed. Use setEditorBinding(Binding) to support more complex cases.

        Note: The same component cannot be used for multiple columns.

        Type Parameters:

        F - a value type

        C - a class that extends both HasValue (for type <F>) and Component

        Parameters:

        editorComponent - the editor component

        Returns:

        this column

        See Also:

        setEditorBinding(Binding), Grid.getEditor(), Binder.bind(HasValue, String), Grid(Class)

      • setRenderer

        public Grid.Column<T,​V> setRenderer​(Renderer<? super V> renderer)

        Sets the Renderer for this Column. Setting the renderer will cause all currently available row data to be recreated and sent to the client. Note: Setting a new renderer will reset presentation provider if it exists.

        Parameters:

        renderer - the new renderer

        Returns:

        this column

        Since:

        8.0.3

      • setRenderer

        public <P> Grid.Column<T,​V> setRenderer​(ValueProvider<V,​P> presentationProvider,
                                                      Renderer<? super P> renderer)

        Sets the Renderer for this Column. Setting the renderer will cause all currently available row data to be recreated and sent to the client.

        The presentation provider is a method that takes the value of this column on a single row, and maps that to a value that the renderer accepts. This feature can be used for storing a complex value in a column for editing, but providing a simplified presentation for the user when not editing.

        Type Parameters:

        P - the presentation type

        Parameters:

        presentationProvider - the function to get presentations from the value of this column, not null

        renderer - the new renderer, not null

        Returns:

        this column

        Since:

        8.1

      • getRenderer

        public Renderer<?> getRenderer()

        Gets the Renderer for this Column.

        Returns:

        the renderer

        Since:

        8.1

      • setHandleWidgetEvents

        public Grid.Column<T,​V> setHandleWidgetEvents​(boolean handleWidgetEvents)

        Sets whether Grid should handle events in this Column from Components and Widgets rendered by certain Renderers. By default the events are not handled.

        Note: Enabling this feature will for example select a row when a component is clicked. For example in the case of a ComboBox or TextField it might be problematic as the component gets re-rendered and might lose focus.

        Parameters:

        handleWidgetEvents - true to handle events; false to not

        Returns:

        this column

        Since:

        8.3

      • isHandleWidgetEvents

        public boolean isHandleWidgetEvents()

        Gets whether Grid is handling the events in this Column from Component and Widgets.

        Returns:

        true if handling events; false if not

        Since:

        8.3

        See Also:

        setHandleWidgetEvents(boolean)

      • getGrid

        protected Grid<T> getGrid()

        Gets the grid that this column belongs to.

        Returns:

        the grid that this column belongs to, or null if this column has not yet been associated with any grid

      • writeDesign

        protected void writeDesign​(org.jsoup.nodes.Element element,
                                   DesignContext designContext)

        Writes the design attributes for this column into given element.

        Parameters:

        element - Element to write attributes into

        designContext - the design context

        Since:

        7.5.0

      • readDesign

        protected void readDesign​(org.jsoup.nodes.Element design,
                                  DesignContext designContext)

        Reads the design attributes for this column from given element.

        Parameters:

        design - Element to read attributes from

        designContext - the design context

        Since:

        7.5.0