com.vaadin.flow.component.grid.
Class Grid.Column<T>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.grid.Grid.Column<T>
-
-
Field Summary
Fields Modifier and Type Field and Description protected Element
footerTemplate
protected Grid<?>
grid
protected Element
headerTemplate
-
Constructor Summary
Constructors Constructor and Description Column(Grid<T> grid, String columnId, Renderer<T> renderer)
Constructs a new Column for use inside a Grid.
-
Method Summary
All Methods 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.SerializableComparator<T>
getComparator(SortDirection sortDirection)
Gets the comparator to use with in-memory sorting for this column when sorting in the given direction.
Element
getElement()
Gets the underlying
<vaadin-grid-column>
element.int
getFlexGrow()
Gets the currently set 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.Stream<QuerySortOrder>
getSortOrder(SortDirection direction)
Gets the sort orders to use with back-end sorting for this column when sorting in the given direction.
String
getWidth()
Gets the width of this column as a CSS-string.
protected boolean
hasSortingIndicators()
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.
boolean
isVisible()
Returns whether this column is visible.
protected void
setBaseHeaderTemplate(String headerTemplate)
Grid.Column<T>
setComparator(Comparator<T> comparator)
Sets a comparator to use with in-memory sorting with this column.
<V extends Comparable<? super V>>
Grid.Column<T>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
.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.
void
setVisible(boolean visible)
Hides or shows the column.
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.
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId
-
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
-
-
-
-
Field Detail
-
grid
protected final Grid<?> grid
-
headerTemplate
protected Element headerTemplate
-
footerTemplate
protected Element footerTemplate
-
-
Method Detail
-
destroyDataGenerators
protected void destroyDataGenerators()
-
getInternalId
protected String getInternalId()
-
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, notnull
Returns:
this column, for method chaining
See Also:
-
getWidth
@Synchronize(value="width-changed") public String getWidth()
Gets the width of this column as a CSS-string.
Returns:
the width of this column as a CSS-string
-
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 ratioReturns:
this column, for method chaining
See Also:
-
getFlexGrow
@Synchronize(value="flex-grow-changed") public int getFlexGrow()
Gets the currently set flex grow value, by default 1.
Returns:
the currently set flex grow value, by default 1
-
setKey
public Grid.Column<T> setKey(String key)
Sets the user-defined identifier to map this column. The key can be used to fetch the column later with
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.
Parameters:
key
- the identifier key, can't benull
Returns:
this column
See Also:
setSortProperty(String...)
,setSortOrderProvider(SortOrderProvider)
-
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 interfaceHasElement
Overrides:
getElement
in classComponent
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)
.Parameters:
comparator
- the comparator to use when sorting data in this columnReturns:
this column
-
setComparator
public <V extends Comparable<? super V>> Grid.Column<T> 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 usingsetSortProperty(String...)
.Note: calling this method automatically sets the column as sortable with
setSortable(boolean)
.Parameters:
keyExtractor
- the value provider used to extract theComparable
sort keyReturns:
this column
See Also:
-
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 byReturns:
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 propertiesReturns:
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 directionReturns:
this column
-
getSortOrder
public Stream<QuerySortOrder> getSortOrder(SortDirection direction)
Gets the sort orders to use with back-end sorting for this column when sorting in the given direction.
Parameters:
direction
- the sorting directionReturns:
stream of sort orders
See Also:
setSortProperty(String...)
,Component.setId(String)
,setSortOrderProvider(SortOrderProvider)
-
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 notReturns:
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 headerReturns:
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 footerReturns:
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 columnReturns:
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 columnReturns:
this column, for method chaining
-
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)
Hides or shows the column. By default columns are visible before explicitly hiding them.
Overrides:
setVisible
in classComponent
Parameters:
visible
-false
to hide the column,true
to show
-
isVisible
@Synchronize(value="hidden-changed") public boolean isVisible()
Returns whether this column is visible. Default is
true
.
-
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)
-
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 T setResizable(boolean resizable)
When set to
true
, the column is user-resizable. By default this is set tofalse
.Parameters:
resizable
- whether to allow user resizing of this columnReturns:
this column, for method chaining
-
isResizable
@Synchronize(value="resizable-changed") public boolean isResizable()
Gets whether this column is user-resizable.
Returns:
whether this column is user-resizable
-
setFrozen
public 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 columnReturns:
this column, for method chaining
-
isFrozen
@Synchronize(value="frozen-changed") public boolean isFrozen()
Gets the this column's frozen state.
Returns:
whether this column is frozen
-
-