T
- type of the underlying grid this column is compatible with@Tag(value="vaadin-grid-column") public static class Grid.Column<T> extends Component
<vaadin-grid-column>
element.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
Grid.removeColumn(Column)
to avoid sending extra data.
Modifier and Type | Field and Description |
---|---|
protected Element |
footerTemplate |
protected Grid<?> |
grid |
protected Element |
headerTemplate |
Constructor and Description |
---|
Column(Grid<T> grid,
String columnId,
Renderer<T> renderer)
Constructs a new Column for use inside a Grid.
|
Modifier and Type | Method and Description |
---|---|
protected String |
addGridSorter(String templateInnerHtml) |
protected void |
destroyDataGenerators() |
protected List<Grid.Column<?>> |
getBottomChildColumns()
Gets recursively the child components of this component that are
instances of Column.
|
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. |
SerializableFunction<T,String> |
getClassNameGenerator()
Gets the function that is used for generating CSS class names for
cells in this column.
|
SerializableComparator<T> |
getComparator(SortDirection sortDirection)
Gets the comparator to use with in-memory sorting for this column
when sorting in the given direction.
|
Component |
getEditorComponent()
Gets the editor component that is used for this column.
|
Element |
getElement()
Gets the underlying
<vaadin-grid-column> element. |
int |
getFlexGrow()
Gets the flex grow value, by default 1.
|
protected Renderer<?> |
getFooterRenderer() |
Grid<?> |
getGrid()
Gets the owner of this column.
|
protected Renderer<?> |
getHeaderRenderer() |
protected String |
getInternalId() |
String |
getKey()
Gets the user-defined key for this column, or
null if no key
has been set. |
Renderer<T> |
getRenderer()
Get the renderer used for this column.
|
Stream<QuerySortOrder> |
getSortOrder(SortDirection direction)
Gets the sort orders to use with back-end sorting for this column
when sorting in the given direction.
|
default ColumnTextAlign |
getTextAlign()
Gets the column text align.
|
String |
getWidth()
Gets the width of this column as a CSS-string.
|
protected boolean |
hasSortingIndicators() |
boolean |
isAutoWidth()
Gets this column's auto width state.
|
default boolean |
isFrozen()
Gets the this column's frozen state.
|
default boolean |
isResizable()
Gets whether this column is user-resizable.
|
boolean |
isSortable()
Gets whether this column is sortable (e.g.
|
Grid.Column<T> |
setAutoWidth(boolean autoWidth)
Enables or disables automatic width for this column.
|
protected void |
setBaseHeaderTemplate(String headerTemplate) |
Grid.Column<T> |
setClassNameGenerator(SerializableFunction<T,String> classNameGenerator)
Sets the function that is used for generating CSS class names for
cells in this column.
|
Grid.Column<T> |
setComparator(Comparator<T> comparator)
Sets a comparator to use with in-memory sorting with this column.
|
<V extends Comparable<? super V>> |
setComparator(ValueProvider<T,V> keyExtractor)
Sets a comparator to use with in-memory sorting with this column
based on the return type of the given
ValueProvider .Sorting
with a back-end is done using
setSortProperty(String[]) . |
Grid.Column<T> |
setEditorComponent(Component editorComponent)
Sets a component to use for editing values of this column in the
editor row.
|
Grid.Column<T> |
setEditorComponent(SerializableFunction<T,? extends Component> componentCallback)
Sets a function that returns the editor component to be used for an
specific item in the editor row.
|
Grid.Column<T> |
setFlexGrow(int flexGrow)
Sets the flex grow ratio for this column.
|
Grid.Column<T> |
setFooter(Component footerComponent)
Sets a footer component to the column.
|
Grid.Column<T> |
setFooter(String labelText)
Sets a footer text to the column.
|
protected void |
setFooterComponent(Component component) |
protected void |
setFooterRenderer(Renderer<?> renderer) |
protected void |
setFooterText(String text) |
default T |
setFrozen(boolean frozen)
Sets this column's frozen state.
|
Grid.Column<T> |
setHeader(Component headerComponent)
Sets a header component to the column.
|
Grid.Column<T> |
setHeader(String labelText)
Sets a header text to the column.
|
protected void |
setHeaderComponent(Component component) |
protected void |
setHeaderRenderer(Renderer<?> renderer) |
protected void |
setHeaderText(String text) |
Grid.Column<T> |
setKey(String key)
Sets the user-defined identifier to map this column.
|
default T |
setResizable(boolean resizable)
When set to
true , the column is user-resizable. |
Grid.Column<T> |
setSortable(boolean sortable)
Sets whether the user can sort this column or not.
|
protected void |
setSortingIndicators(boolean sortingIndicators)
Sets this component to show sorting indicators or not.
|
Grid.Column<T> |
setSortOrderProvider(SortOrderProvider provider)
Sets the sort orders when sorting this column.
|
Grid.Column<T> |
setSortProperty(String... properties)
Sets strings describing back end properties to be used when sorting
this column.
|
default T |
setTextAlign(ColumnTextAlign textAlign)
Sets the column text align.
|
void |
setVisible(boolean visible)
Sets the component visibility value.
|
Grid.Column<T> |
setWidth(String width)
Sets the width of this column as a CSS-string.
|
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.
|
addListener, fireEvent, from, get, getChildren, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addAttachListener
addDetachListener
protected final Grid<?> grid
protected Element headerTemplate
protected Element footerTemplate
protected void destroyDataGenerators()
protected String getInternalId()
public Renderer<T> getRenderer()
Note: Mutating the renderer after the Grid has been rendered on the client will not change the column, and can lead to undefined behavior.
null
public Grid.Column<T> setWidth(String width)
width
- the width to set this column to, as a CSS-string, not
null
setFlexGrow(int)
@Synchronize(value="column-drag-resize") public String getWidth()
Grid.addColumnResizeListener(ComponentEventListener)
public Grid.Column<T> setFlexGrow(int flexGrow)
flexGrow
- the flex grow ratiosetWidth(String)
@Synchronize(value="column-drag-resize") public int getFlexGrow()
Grid.addColumnResizeListener(ComponentEventListener)
public Grid.Column<T> setAutoWidth(boolean autoWidth)
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.
autoWidth
- whether to enable or disable automatic width on this
columnGrid.recalculateColumnWidths()
,
setFlexGrow(int)
public boolean isAutoWidth()
public Grid.Column<T> setKey(String key)
Grid.getColumnByKey(String)
.
The key is also used as the backend sort property
for this column if no sort property or sort
order provider has been set for this column.
The key has to be unique within the grid, and it can't be changed after set once.
key
- the identifier key, can't be null
setSortProperty(String...)
,
setSortOrderProvider(SortOrderProvider)
public String getKey()
null
if no key
has been set.public Element getElement()
<vaadin-grid-column>
element.
It is highly discouraged to directly use the API exposed by the returned element.
getElement
in interface HasElement
getElement
in class Component
public Grid.Column<T> setComparator(Comparator<T> comparator)
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.
comparator
- the comparator to use when sorting data in this columnpublic <V extends Comparable<? super V>> Grid.Column<T> setComparator(ValueProvider<T,V> keyExtractor)
ValueProvider
.Sorting
with a back-end is done using
setSortProperty(String[])
.
Note: calling this method automatically sets the
column as sortable with setSortable(boolean)
.
V
- the value of the columnkeyExtractor
- the value provider used to extract the Comparable
sort keyComparator.comparing(java.util.function.Function)
public SerializableComparator<T> getComparator(SortDirection sortDirection)
Note: calling this method automatically sets the
column as sortable with setSortable(boolean)
.
sortDirection
- the direction this column is sorted bypublic Grid.Column<T> setSortProperty(String... properties)
Note: calling this method automatically sets the
column as sortable with setSortable(boolean)
.
properties
- the array of strings describing backend propertiespublic Grid.Column<T> setSortOrderProvider(SortOrderProvider provider)
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)
.
provider
- the function to use when generating sort orders with the
given directionpublic Stream<QuerySortOrder> getSortOrder(SortDirection direction)
direction
- the sorting directionsetSortProperty(String...)
,
Component.setId(String)
,
setSortOrderProvider(SortOrderProvider)
public Grid.Column<T> setSortable(boolean sortable)
sortable
- true
if the column can be sorted by the user;
false
if notpublic boolean isSortable()
true
if the column is sortable,
false
otherwisepublic Grid.Column<T> setHeader(String labelText)
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.
labelText
- the text to be shown at the column headerpublic Grid.Column<T> setFooter(String labelText)
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.
labelText
- the text to be shown at the column footerpublic Grid.Column<T> setHeader(Component headerComponent)
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.
headerComponent
- the component to be used in the header of the columnpublic Grid.Column<T> setFooter(Component footerComponent)
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.
footerComponent
- the component to be used in the footer of the columnpublic Grid.Column<T> setEditorComponent(Component editorComponent)
setEditorComponent(SerializableFunction)
to support more
complex cases.editorComponent
- the editor component, or null
to remove the
editor component for this columnGrid.getEditor()
,
Binder.bind(HasValue, ValueProvider, Setter)
public Grid.Column<T> setEditorComponent(SerializableFunction<T,? extends Component> componentCallback)
componentCallback
- the editor component function, or null
to
remove the editor component for this columnGrid.getEditor()
,
setEditorComponent(Component)
public Component getEditorComponent()
null
if no component is
set, or if it was set by using
setEditorComponent(SerializableFunction)
.setEditorComponent(Component)
public Grid.Column<T> setClassNameGenerator(SerializableFunction<T,String> classNameGenerator)
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.
classNameGenerator
- the class name generator to set, not null
NullPointerException
- if classNameGenerator
is null
Grid.setClassNameGenerator(SerializableFunction)
public SerializableFunction<T,String> getClassNameGenerator()
protected Grid.Column<?> getBottomLevelColumn()
<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).public Grid<?> getGrid()
public void setVisible(boolean visible)
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.
setVisible
in class Component
visible
- the component visibility valueGrid.removeColumn(Column)
protected void setHeaderRenderer(Renderer<?> renderer)
protected void setFooterRenderer(Renderer<?> renderer)
protected void setHeaderText(String text)
protected void setFooterText(String text)
protected void setHeaderComponent(Component component)
protected void setFooterComponent(Component component)
protected Renderer<?> getHeaderRenderer()
protected Renderer<?> getFooterRenderer()
protected void updateSortingIndicators(boolean sortable)
sortable
- true
to have sorting indicators if the column is
sortable, false
to not have sorting indicatorsprotected void setSortingIndicators(boolean sortingIndicators)
sortingIndicators
- true
to show sorting indicators, false
to
remove themprotected boolean hasSortingIndicators()
protected void setBaseHeaderTemplate(String headerTemplate)
protected List<Grid.Column<?>> getBottomChildColumns()
public T setResizable(boolean resizable)
true
, the column is user-resizable. By default this
is set to false
.resizable
- whether to allow user resizing of this column@Synchronize(value="resizable-changed") public boolean isResizable()
public T setFrozen(boolean frozen)
Note: Columns are frozen in-place, freeze columns from left to right for a consistent outcome.
frozen
- whether to freeze or unfreeze this column@Synchronize(value="frozen-changed") public boolean isFrozen()
public T setTextAlign(ColumnTextAlign textAlign)
textAlign
- the text alignment of the column. Setting it to
null
resets the alignment to the default value
ColumnTextAlign.START
.@Synchronize(value="text-align-changed") public ColumnTextAlign getTextAlign()
ColumnTextAlign.START
.null
Copyright © 2025. All rights reserved.