T
- the grid bean type@Tag(value="vaadin-grid") @HtmlImport(value="frontend://bower_components/vaadin-grid/src/vaadin-grid.html") @HtmlImport(value="frontend://bower_components/vaadin-grid/src/vaadin-grid-column.html") @HtmlImport(value="frontend://bower_components/vaadin-grid/src/vaadin-grid-sorter.html") @HtmlImport(value="frontend://bower_components/vaadin-checkbox/src/vaadin-checkbox.html") @HtmlImport(value="frontend://flow-component-renderer.html") @JavaScript(value="frontend://gridConnector.js") public class Grid<T> extends Component implements HasDataProvider<T>, HasStyle, HasSize, Focusable<Grid<T>>, SortEvent.SortNotifier<Grid<T>,GridSortOrder<T>>, HasTheme, HasDataGenerators<T>
<vaadin-grid>
element.Modifier and Type | Class and Description |
---|---|
static class |
Grid.AbstractGridExtension<T>
A helper base class for creating extensions for the Grid component.
|
static class |
Grid.Column<T>
Server-side component for the
<vaadin-grid-column> element. |
protected static class |
Grid.DataCommunicatorBuilder<T,U extends ArrayUpdater>
Builder for
DataCommunicator object. |
static class |
Grid.SelectionMode
Selection mode representing the built-in selection models in grid.
|
protected static class |
Grid.UpdateQueue |
BlurNotifier.BlurEvent<C extends Component>
FocusNotifier.FocusEvent<C extends Component>
Modifier | Constructor and Description |
---|---|
|
Grid()
Creates a new instance, with page size of 50.
|
|
Grid(Class<T> beanType)
Creates a new grid with an initial set of columns for each of the bean's
properties.
|
|
Grid(Class<T> beanType,
boolean autoCreateColumns)
Creates a new grid with an initial set of columns for each of the bean's
properties.
|
protected |
Grid(Class<T> beanType,
SerializableBiFunction<GridArrayUpdater.UpdateQueueData,Integer,Grid.UpdateQueue> updateQueueBuidler,
B dataCommunicatorBuilder)
Creates a new grid with an initial set of columns for each of the bean's
properties.
|
|
Grid(int pageSize)
Creates a new instance, with the specified page size.
|
protected |
Grid(int pageSize,
SerializableBiFunction<GridArrayUpdater.UpdateQueueData,Integer,Grid.UpdateQueue> updateQueueBuidler,
B dataCommunicatorBuilder)
Creates a new instance, with the specified page size and data
communicator.
|
Modifier and Type | Method and Description |
---|---|
Grid.Column<T> |
addColumn(Renderer<T> renderer)
Adds a new text column to this
Grid with a renderer and default
column factory. |
protected <C extends Grid.Column<T>> |
addColumn(Renderer<T> renderer,
BiFunction<Renderer<T>,String,C> columnFactory)
Adds a new text column to this
Grid with a renderer and column
factory provided. |
protected <C extends Grid.Column<T>> |
addColumn(Renderer<T> renderer,
BiFunction<Renderer<T>,String,C> columnFactory,
String... sortingProperties)
Adds a new text column to this
Grid with a template renderer, sorting properties
and column factory provided. |
Grid.Column<T> |
addColumn(Renderer<T> renderer,
String... sortingProperties)
Adds a new text column to this
Grid with a template renderer, sorting properties
and default column factory. |
Grid.Column<T> |
addColumn(String propertyName)
Adds a new column for the given property name with the default column factory.
|
protected <C extends Grid.Column<T>> |
addColumn(String propertyName,
BiFunction<Renderer<T>,String,C> columnFactory)
Adds a new column for the given property name with the column factory provided.
|
Grid.Column<T> |
addColumn(ValueProvider<T,?> valueProvider)
Adds a new text column to this
Grid with a value provider and
default column factory. |
protected <C extends Grid.Column<T>> |
addColumn(ValueProvider<T,?> valueProvider,
BiFunction<Renderer<T>,String,C> columnFactory)
Adds a new text column to this
Grid with a value provider and
column factory provided. |
<V extends Comparable<? super V>> |
addColumn(ValueProvider<T,V> valueProvider,
String... sortingProperties)
Adds a new text column to this
Grid with a value provider and
sorting properties.The value is converted to a JSON value by using
JsonSerializer.toJson(Object) . |
void |
addColumns(String... propertyNames)
Adds a new columns for the given property names.
|
<V extends Component> |
addComponentColumn(ValueProvider<T,V> componentProvider)
Adds a new column that shows components.
|
GridContextMenu<T> |
addContextMenu()
Adds a new context-menu for this grid.
|
Registration |
addDataGenerator(DataGenerator<T> dataGenerator)
Adds the given data generator.
|
protected HeaderRow |
addFirstHeaderRow() |
Registration |
addItemClickListener(ComponentEventListener<ItemClickEvent<T>> listener)
Adds an item click listener to this component.
|
Registration |
addItemDoubleClickListener(ComponentEventListener<ItemDoubleClickEvent<T>> listener)
Adds an item double click listener to this component.
|
Registration |
addSelectionListener(SelectionListener<Grid<T>,T> listener)
Adds a selection listener to the current selection model.
|
Registration |
addSortListener(ComponentEventListener<SortEvent<Grid<T>,GridSortOrder<T>>> listener)
Adds a sort order change listener that gets notified when the sort
order changes.
|
void |
addThemeVariants(GridVariant... variants)
Adds theme variants to the component.
|
Registration |
addValueProvider(String property,
ValueProvider<T,?> valueProvider)
Adds a ValueProvider to this Grid that is not tied to a Column.
|
FooterRow |
appendFooterRow()
Adds a new footer row to the bottom of the existing footer rows.
|
HeaderRow |
appendHeaderRow()
Adds a new header row to the bottom of the existing header rows.
|
MultiSelect<Grid<T>,T> |
asMultiSelect()
Use this grid as a multiselect in
Binder . |
SingleSelect<Grid<T>,T> |
asSingleSelect()
Use this grid as a single select in
Binder . |
protected static int |
compareMaybeComparables(Object a,
Object b) |
protected Grid.Column<T> |
createColumn(Renderer<T> renderer,
String columnId)
Deprecated.
This method should not be used outside.
getDefaultColumnFactory() should
be used instead. |
protected String |
createColumnId(boolean increment) |
protected GridArrayUpdater |
createDefaultArrayUpdater(SerializableBiFunction<GridArrayUpdater.UpdateQueueData,Integer,Grid.UpdateQueue> updateQueueFactory) |
protected Editor<T> |
createEditor()
Creates a new Editor instance.
|
protected SerializableComparator<T> |
createSortingComparator()
Creates a comparator for grid to sort rows.
|
void |
deselect(T item)
This method is a shorthand that delegates to the currently set selection
model.
|
void |
deselectAll()
This method is a shorthand that delegates to the currently set selection
model.
|
protected GridArrayUpdater |
getArrayUpdater() |
SerializableFunction<T,String> |
getClassNameGenerator()
Gets the function that is used for generating CSS class names for rows in
this grid.
|
Grid.Column<T> |
getColumnByKey(String columnKey)
Gets a
Grid.Column of this grid by its key. |
protected List<com.vaadin.flow.component.grid.ColumnLayer> |
getColumnLayers() |
List<Grid.Column<T>> |
getColumns()
Gets an unmodifiable list of all
Grid.Column s currently in this
Grid . |
DataCommunicator<T> |
getDataCommunicator()
Returns the data communicator of this Grid.
|
DataProvider<T,?> |
getDataProvider()
Returns the data provider of this grid.
|
protected BiFunction<Renderer<T>,String,Grid.Column<T>> |
getDefaultColumnFactory()
Gives a reference to the column factory.
|
protected HeaderRow |
getDefaultHeaderRow() |
Editor<T> |
getEditor()
Gets the editor.
|
List<FooterRow> |
getFooterRows()
Gets all of the footer rows in the Grid, in order from top to bottom.
|
List<HeaderRow> |
getHeaderRows()
Gets all of the header rows in the Grid, in order from top to bottom.
|
int |
getPageSize()
Gets the current page size, which is the number of items fetched at a
time from the dataprovider.
|
PropertySet<T> |
getPropertySet()
Returns
PropertySet of bean this Grid is constructed with via
Grid(Class) . |
Set<T> |
getSelectedItems()
This method is a shorthand that delegates to the currently set selection
model.
|
GridSelectionModel<T> |
getSelectionModel()
Returns the selection model for this grid.
|
List<GridSortOrder<T>> |
getSortOrder()
Gets an list of the current sort orders in the Grid.
|
protected String |
getUniqueKeyProperty()
Gets property name for unique key in row's generated JSON.
|
protected ValueProvider<T,String> |
getUniqueKeyProvider()
Gets optional value provider for unique key in row's generated JSON.
|
protected void |
initConnector() |
protected com.vaadin.flow.component.grid.ColumnLayer |
insertColumnLayer(int index,
List<com.vaadin.flow.component.grid.AbstractColumn<?>> columns)
Creates a new layer from the provided columns, inserts the layer into
given index and returns the new layer.
|
boolean |
isColumnReorderingAllowed()
Returns whether column reordering is allowed.
|
boolean |
isDetailsVisible(T item)
Returns the visibility of details component for given item.
|
boolean |
isDetailsVisibleOnClick()
Gets whether the item details are opened and closed by clicking the rows
or not.
|
boolean |
isHeightByRows()
Gets whether grid's height is defined by the number of its rows.
|
boolean |
isMultiSort()
Gets whether multiple column sorting is enabled on the client-side.
|
boolean |
isVerticalScrollingEnabled()
Gets whether the vertical scrolling on the Grid web component is enabled.
|
protected void |
onDataProviderChange()
Callback which is called if a new data provider is set or any change
happen in the current data provider (an
DataChangeEvent event is
fired). |
void |
onEnabledStateChanged(boolean enabled)
Handle component enable state when the enabled state changes.
|
FooterRow |
prependFooterRow()
Adds a new footer row on the top of the existing footer rows.
|
HeaderRow |
prependHeaderRow()
Adds a new header row on the top of the existing header rows.
|
void |
removeAllColumns()
Removes all columns from this Grid.
|
void |
removeColumn(Grid.Column<T> column)
Removes a column from the Grid.
|
void |
removeColumnByKey(String columnKey)
Removes a column with the given column key from the Grid.
|
protected void |
removeColumnLayer(com.vaadin.flow.component.grid.ColumnLayer layer)
Removes the given layer and moves the columns on the lower level to its
place.
|
void |
removeDataGenerator(DataGenerator<T> dataGenerator)
Removes the given data generator.
|
void |
removeThemeVariants(GridVariant... variants)
Removes theme variants from the component.
|
void |
select(T item)
This method is a shorthand that delegates to the currently set selection
model.
|
void |
setClassNameGenerator(SerializableFunction<T,String> classNameGenerator)
Sets the function that is used for generating CSS class names for rows in
this grid.
|
protected void |
setColumnKey(String key,
Grid.Column column)
Sets a user-defined identifier for given column.
|
void |
setColumnReorderingAllowed(boolean columnReorderingAllowed)
Sets whether or not column reordering is allowed.
|
void |
setColumns(String... propertyNames)
Sets the columns and their order based on the given properties.
|
void |
setDataProvider(DataProvider<T,?> dataProvider)
Sets the data provider for this listing.
|
void |
setDetailsVisible(T item,
boolean visible)
Sets the visibility of details component for given item.
|
void |
setDetailsVisibleOnClick(boolean detailsVisibleOnClick)
Sets whether the item details can be opened and closed by clicking the
rows or not.
|
void |
setHeightByRows(boolean heightByRows)
If
true , the grid's height is defined by the number of its
rows. |
void |
setItemDetailsRenderer(Renderer<T> renderer)
Set the renderer to use for displaying the item details rows in this
grid.
|
void |
setMultiSort(boolean multiSort)
Sets whether multiple column sorting is enabled on the client-side.
|
void |
setPageSize(int pageSize)
Sets the page size, which is the number of items fetched at a time from
the dataprovider.
|
GridSelectionModel<T> |
setSelectionMode(Grid.SelectionMode selectionMode)
Sets the grid's selection mode.
|
protected void |
setSelectionModel(GridSelectionModel<T> model,
Grid.SelectionMode selectionMode)
Sets the selection model for the grid.
|
void |
setSortableColumns(String... propertyNames)
Sets the defined columns as sortable, based on the given property names.
|
protected void |
setUniqueKeyProperty(String uniqueKeyProperty)
Sets property name for unique key in row's generated JSON.
|
protected void |
setUniqueKeyProvider(ValueProvider<T,String> uniqueKeyProvider)
Sets value provider for unique key in row's generated JSON.
|
void |
setVerticalScrollingEnabled(boolean enabled)
Enables or disables the vertical scrolling on the Grid web component.
|
void |
sort(List<GridSortOrder<T>> order)
Forces a defined sort order for the columns in the Grid.
|
protected void |
updateSelectionModeOnClient() |
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setItems
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
getHeight, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, setHeight, setHeightFull, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFull
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
isEnabled, setEnabled
getElement
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
addAttachListener
addDetachListener
public Grid()
public Grid(int pageSize)
The page size influences the Query.getLimit()
sent by the client,
but it's up to the webcomponent to determine the actual query limit,
based on the height of the component and scroll position. Usually the
limit is 3 times the page size (e.g. 150 items with a page size of 50).
pageSize
- the page size. Must be greater than zero.public Grid(Class<T> beanType, boolean autoCreateColumns)
column keys
and the property captions will
be used as the column headers
. The
generated columns will be sortable by default, if the property is
Comparable
.
When autoCreateColumns is true
, only the direct properties
of the bean are included and they will be in alphabetical order. Use
setColumns(String...)
to define which properties to include
and in which order. You can also add a column for an individual property
with addColumn(String)
. Both of these methods support also
sub-properties with dot-notation, eg.
"property.nestedProperty"
.
beanType
- the bean type to use, not null
autoCreateColumns
- when true
, columns are created automatically for
the properties of the beanTypepublic Grid(Class<T> beanType)
column keys
and the property captions will
be used as the column headers
. The
generated columns will be sortable by default, if the property is
Comparable
.
By default, only the direct properties of the bean are included and they
will be in alphabetical order. Use setColumns(String...)
to
define which properties to include and in which order. You can also add a
column for an individual property with addColumn(String)
. Both
of these methods support also sub-properties with dot-notation, eg.
"property.nestedProperty"
.
beanType
- the bean type to use, not null
protected Grid(Class<T> beanType, SerializableBiFunction<GridArrayUpdater.UpdateQueueData,Integer,Grid.UpdateQueue> updateQueueBuidler, B dataCommunicatorBuilder)
column keys
and the property captions will
be used as the column headers
.
You can add columns for nested properties of the bean with
addColumn(String)
.
B
- the data communicator builder typeU
- the GridArrayUpdater typebeanType
- the bean type to use, not null
updateQueueBuidler
- the builder for new Grid.UpdateQueue
instancedataCommunicatorBuilder
- Builder for DataCommunicator
implementation this Grid
uses to handle all data communication.protected Grid(int pageSize, SerializableBiFunction<GridArrayUpdater.UpdateQueueData,Integer,Grid.UpdateQueue> updateQueueBuidler, B dataCommunicatorBuilder)
The page size influences the Query.getLimit()
sent by the client,
but it's up to the webcomponent to determine the actual query limit,
based on the height of the component and scroll position. Usually the
limit is 3 times the page size (e.g. 150 items with a page size of 50).
B
- the data communicator builder typeU
- the GridArrayUpdater typepageSize
- the page size. Must be greater than zero.updateQueueBuidler
- the builder for new Grid.UpdateQueue
instancedataCommunicatorBuilder
- Builder for DataCommunicator
implementation this Grid
uses to handle all data communication.protected void initConnector()
protected GridArrayUpdater createDefaultArrayUpdater(SerializableBiFunction<GridArrayUpdater.UpdateQueueData,Integer,Grid.UpdateQueue> updateQueueFactory)
public Grid.Column<T> addColumn(ValueProvider<T,?> valueProvider)
Grid
with a value provider and
default column factory. The value is converted to String when sent to
the client by using String.valueOf(Object)
.
NOTE: For displaying components, see
addComponentColumn(ValueProvider)
. For using build-in renderers,
see addColumn(Renderer)
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
NOTE: This method is a shorthand for addColumn(ValueProvider, BiFunction)
valueProvider
- the value provideraddComponentColumn(ValueProvider)
,
addColumn(Renderer)
,
removeColumn(Column)
,
getDefaultColumnFactory()
,
addColumn(ValueProvider, BiFunction)
protected <C extends Grid.Column<T>> C addColumn(ValueProvider<T,?> valueProvider, BiFunction<Renderer<T>,String,C> columnFactory)
Grid
with a value provider and
column factory provided. The value is converted to String when sent to
the client by using String.valueOf(Object)
.
NOTE: For displaying components, see
addComponentColumn(ValueProvider)
. For using build-in renderers,
see addColumn(Renderer)
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
valueProvider
- the value providercolumnFactory
- the method that creates a new column instance for this Grid
instance.addColumn(ValueProvider)
,
addComponentColumn(ValueProvider)
,
addColumn(Renderer)
,
removeColumn(Column)
public <V extends Component> Grid.Column<T> addComponentColumn(ValueProvider<T,V> componentProvider)
This is a shorthand for addColumn(Renderer)
with a
ComponentRenderer
.
NOTE: Using ComponentRenderer
is not as efficient as the
built in renderers or using TemplateRenderer
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
V
- the component typecomponentProvider
- a value provider that will return a component for the given
itemaddColumn(Renderer)
,
removeColumn(Column)
public <V extends Comparable<? super V>> Grid.Column<T> addColumn(ValueProvider<T,V> valueProvider, String... sortingProperties)
Grid
with a value provider and
sorting properties.The value is converted to a JSON value by using
JsonSerializer.toJson(Object)
. The sorting properties are used to
configure backend sorting for this column. In-memory sorting is
automatically configured using the return type of the given
ValueProvider
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
V
- the type of the columnvalueProvider
- the value providersortingProperties
- the sorting properties to use with this columnGrid.Column.setComparator(ValueProvider)
,
Grid.Column.setSortProperty(String...)
,
removeColumn(Column)
public Grid.Column<T> addColumn(Renderer<T> renderer)
Grid
with a renderer and default
column factory.
See implementations of the Renderer
interface for built-in
renderer options with type safe APIs. For a renderer using template
binding, use TemplateRenderer.of(String)
.
NOTE: You can add component columns easily using the
addComponentColumn(ValueProvider)
, but using
ComponentRenderer
is not as efficient as the built in renderers
or using TemplateRenderer
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
NOTE: This method is a shorthand for addColumn(Renderer, BiFunction)
renderer
- the renderer used to create the grid cell structuregetDefaultColumnFactory()
,
TemplateRenderer.of(String)
,
addComponentColumn(ValueProvider)
,
removeColumn(Column)
,
addColumn(Renderer, BiFunction)
protected <C extends Grid.Column<T>> C addColumn(Renderer<T> renderer, BiFunction<Renderer<T>,String,C> columnFactory)
Grid
with a renderer and column
factory provided.
See implementations of the Renderer
interface for built-in
renderer options with type safe APIs. For a renderer using template
binding, use TemplateRenderer.of(String)
.
NOTE: You can add component columns easily using the
addComponentColumn(ValueProvider)
, but using
ComponentRenderer
is not as efficient as the built in renderers
or using TemplateRenderer
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
renderer
- the renderer used to create the grid cell structurecolumnFactory
- the method that creates a new column instance for this Grid
instance.addColumn(Renderer)
,
TemplateRenderer.of(String)
,
addComponentColumn(ValueProvider)
,
removeColumn(Column)
@Deprecated protected Grid.Column<T> createColumn(Renderer<T> renderer, String columnId)
getDefaultColumnFactory()
should
be used instead.Grid
instance.
This method must not return null
.
renderer
- the renderer used to create the grid cell structurecolumnId
- internal column idcreateColumnId(boolean)
,
Renderer
protected BiFunction<Renderer<T>,String,Grid.Column<T>> getDefaultColumnFactory()
This method must not return null
.
public Grid.Column<T> addColumn(Renderer<T> renderer, String... sortingProperties)
Grid
with a template renderer, sorting properties
and default column factory. The values inside the renderer are converted to JSON
values by using JsonSerializer.toJson(Object)
.
NOTE: You can add component columns easily using the
addComponentColumn(ValueProvider)
, but using
ComponentRenderer
is not as efficient as the built in renderers
or using TemplateRenderer
.
This constructor attempts to automatically configure both in-memory and backend sorting using the given sorting properties and matching those with the property names used in the given renderer.
Note: if a property of the renderer that is used as a sorting property does not extend Comparable, no in-memory sorting is configured for it.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
Note: This method is a shorthand for ##addColumn(Renderer, BiFunction, String...)
renderer
- the renderer used to create the grid cell structuresortingProperties
- the sorting properties to use for this columngetDefaultColumnFactory()
,
addColumn(Renderer, BiFunction, String...)
,
removeColumn(Column)
protected <C extends Grid.Column<T>> C addColumn(Renderer<T> renderer, BiFunction<Renderer<T>,String,C> columnFactory, String... sortingProperties)
Grid
with a template renderer, sorting properties
and column factory provided. The values inside the renderer are converted to JSON
values by using JsonSerializer.toJson(Object)
.
NOTE: You can add component columns easily using the
addComponentColumn(ValueProvider)
, but using
ComponentRenderer
is not as efficient as the built in renderers
or using TemplateRenderer
.
This constructor attempts to automatically configure both in-memory and backend sorting using the given sorting properties and matching those with the property names used in the given renderer.
Note: if a property of the renderer that is used as a sorting property does not extend Comparable, no in-memory sorting is configured for it.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
renderer
- the renderer used to create the grid cell structurecolumnFactory
- the method that creates a new column instance for this Grid
instance.sortingProperties
- the sorting properties to use for this columnaddColumn(Renderer, String...)
,
removeColumn(Column)
public Grid.Column<T> addColumn(String propertyName)
column key
and the property
caption will be used as the column
header
.
You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
If the property is Comparable
, the created column is sortable by
default. This can be changed with the Grid.Column.setSortable(boolean)
method.
Note: This method can only be used for a Grid created
from a bean type with Grid(Class)
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
Note: This method is a shorthand for addColumn(String, BiFunction)
propertyName
- the property name of the new column, not null
getDefaultColumnFactory()
,
addColumn(String, BiFunction)
,
removeColumn(Column)
protected <C extends Grid.Column<T>> C addColumn(String propertyName, BiFunction<Renderer<T>,String,C> columnFactory)
column key
and the property
caption will be used as the column
header
.
You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
If the property is Comparable
, the created column is sortable by
default. This can be changed with the Grid.Column.setSortable(boolean)
method.
Note: This method can only be used for a Grid created
from a bean type with Grid(Class)
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
propertyName
- the property name of the new column, not null
columnFactory
- the method that creates a new column instance for this Grid
instance.addColumn(String)
,
removeColumn(Column)
public void addColumns(String... propertyNames)
column key
and the
properties' caption will be used as the column header
.
You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
If the property is Comparable
, the created column is sortable by
default. This can be changed with the Grid.Column.setSortable(boolean)
method.
Note: This method can only be used for a Grid created
from a bean type with Grid(Class)
.
Every added column sends data to the client side regardless of its
visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.
propertyNames
- the property names of the new columns, not null
addColumn(String)
,
removeColumn(Column)
public void setColumns(String... propertyNames)
This is a shortcut for removing all columns and then calling
addColumn(String)
for each of the given propertyNames.
You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
Note that this also resets the headers and footers.
Note: This method can only be used for a Grid created
from a bean type with Grid(Class)
.
propertyNames
- the properties to create columns forpublic void setSortableColumns(String... propertyNames)
This is a shortcut for setting all columns not sortable and then calling
Grid.Column.setSortable(boolean)
for each of the columns defined by
the given propertyNames.
You can set sortable columns for nested properties with dot notation, eg.
"property.nestedProperty"
Note: This method can only be used for a Grid created
from a bean type with Grid(Class)
.
propertyNames
- the property names used to reference the columnsIllegalArgumentException
- if any of the propertyNames refers to a non-existing columnsetColumns(String...)
,
getColumnByKey(String)
protected void setColumnKey(String key, Grid.Column column)
column
- the columnkey
- the user-defined identifierGrid.Column.setKey(String)
protected String createColumnId(boolean increment)
public HeaderRow prependHeaderRow()
If there are no existing header rows, this will create the first row.
public HeaderRow appendHeaderRow()
If there are no existing header rows, this will create the first row.
protected HeaderRow addFirstHeaderRow()
protected HeaderRow getDefaultHeaderRow()
public FooterRow prependFooterRow()
If there are no existing footer rows, this will create the first row.
public FooterRow appendFooterRow()
If there are no existing footer rows, this will create the first row.
protected List<com.vaadin.flow.component.grid.ColumnLayer> getColumnLayers()
public List<HeaderRow> getHeaderRows()
public List<FooterRow> getFooterRows()
public void addThemeVariants(GridVariant... variants)
variants
- theme variants to addpublic void removeThemeVariants(GridVariant... variants)
variants
- theme variants to removeprotected com.vaadin.flow.component.grid.ColumnLayer insertColumnLayer(int index, List<com.vaadin.flow.component.grid.AbstractColumn<?>> columns)
The user of this method should make sure that the DOM corresponds the column layer structure.
index
- the index to insertcolumns
- the column components that the new layer will wrapprotected void removeColumnLayer(com.vaadin.flow.component.grid.ColumnLayer layer)
layer
- the layer to remove, not the bottom layerpublic void setDataProvider(DataProvider<T,?> dataProvider)
HasDataProvider
setDataProvider
in interface HasDataProvider<T>
dataProvider
- the data provider, not nullpublic DataProvider<T,?> getDataProvider()
null
public DataCommunicator<T> getDataCommunicator()
null
public int getPageSize()
public void setPageSize(int pageSize)
Note: the number of items in the server-side memory can be considerably higher than the page size, since the component can show more than one page at a time.
Setting the pageSize after the Grid has been rendered effectively resets the component, and the current page(s) and sent over again.
pageSize
- the maximum number of items sent per request. Should be
greater than zeropublic GridSelectionModel<T> getSelectionModel()
protected void setSelectionModel(GridSelectionModel<T> model, Grid.SelectionMode selectionMode)
This method is for setting a custom selection model, and is
protected
because setSelectionMode(SelectionMode)
should
be used for easy switching between built-in selection models.
The default selection model is GridSingleSelectionModel
.
To use a custom selection model, you can e.g. extend the grid call this method with your custom selection model.
model
- the selection model to use, not null
selectionMode
- the selection mode this selection model corresponds to, not
null
setSelectionMode(SelectionMode)
protected void updateSelectionModeOnClient()
public GridSelectionModel<T> setSelectionMode(Grid.SelectionMode selectionMode)
To use your custom selection model, you can use
setSelectionModel(GridSelectionModel, SelectionMode)
, see
existing selection model implementations for example.
selectionMode
- the selection mode to switch to, not null
Grid.SelectionMode
,
GridSelectionModel
,
setSelectionModel(GridSelectionModel, SelectionMode)
public SingleSelect<Grid<T>,T> asSingleSelect()
Binder
.
Throws IllegalStateException
if the grid is not using a
GridSingleSelectionModel
.
IllegalStateException
- if not using a single selection modelpublic MultiSelect<Grid<T>,T> asMultiSelect()
Binder
.
Throws IllegalStateException
if the grid is not using a
GridMultiSelectionModel
.
IllegalStateException
- if not using a multiselection modelpublic Set<T> getSelectedItems()
null
getSelectionModel()
,
GridSelectionModel
public void select(T item)
item
- the item to selectgetSelectionModel()
,
GridSelectionModel
public void deselect(T item)
item
- the item to deselectgetSelectionModel()
,
GridSelectionModel
public void deselectAll()
getSelectionModel()
,
GridSelectionModel
public Registration addSelectionListener(SelectionListener<Grid<T>,T> listener)
This is a shorthand for
grid.getSelectionModel().addSelectionListener()
. To get more
detailed selection events, use getSelectionModel()
and either
GridSingleSelectionModel.addSingleSelectionListener(SingleSelectionListener)
or
GridMultiSelectionModel.addMultiSelectionListener(MultiSelectionListener)
depending on the used selection mode.
listener
- the listener to addUnsupportedOperationException
- if selection has been disabled with
Grid.SelectionMode.NONE
public void setItemDetailsRenderer(Renderer<T> renderer)
renderer
- the renderer to use for displaying item details rows,
null
to remove the current renderer@Synchronize(value="column-reordering-allowed-changed") public boolean isColumnReorderingAllowed()
false
.public void setColumnReorderingAllowed(boolean columnReorderingAllowed)
false
.columnReorderingAllowed
- specifies whether column reordering is allowedpublic List<Grid.Column<T>> getColumns()
Grid.Column
s currently in this
Grid
.
Note: If column reordering is enabled with
setColumnReorderingAllowed(boolean)
and the user has reordered
the columns, the order of the list returned by this method might not be
correct.
public Grid.Column<T> getColumnByKey(String columnKey)
Grid.Column
of this grid by its key.columnKey
- the identifier key of the column to getnull
if no column has such keyGrid.Column.setKey(String)
public void removeColumnByKey(String columnKey)
columnKey
- the key of the column, assigned by
Grid.Column.setKey(String)
, or automatically created when
using Grid(Class)
. Cannot be null
IllegalArgumentException
- if the column is not part of this Gridpublic void removeColumn(Grid.Column<T> column)
column
- the column to be removed, not null
IllegalArgumentException
- if column is null
or if it is not part of this
Gridpublic void removeAllColumns()
public void setDetailsVisible(T item, boolean visible)
item
- the item to show details forvisible
- true
if details component should be visible;
false
if it should be hiddenpublic void setDetailsVisibleOnClick(boolean detailsVisibleOnClick)
detailsVisibleOnClick
- true
to enable opening and closing item details by
clicking the rows, false
to disable this functionalitysetItemDetailsRenderer(Renderer)
public boolean isDetailsVisibleOnClick()
true
if clicking the rows opens and closes their item
details, false
otherwisesetItemDetailsRenderer(Renderer)
public boolean isDetailsVisible(T item)
item
- the item to show details fortrue
if details component should be visible;
false
if it should be hiddenpublic Registration addSortListener(ComponentEventListener<SortEvent<Grid<T>,GridSortOrder<T>>> listener)
SortEvent.SortNotifier
addSortListener
in interface SortEvent.SortNotifier<Grid<T>,GridSortOrder<T>>
listener
- the sort order change listener to addpublic void setMultiSort(boolean multiSort)
multiSort
- true
to enable sorting of multiple columns on the
client-side, false
to disablepublic boolean isMultiSort()
true
if sorting of multiple columns is enabled,
false
otherwisesetMultiSort(boolean)
public GridContextMenu<T> addContextMenu()
public void sort(List<GridSortOrder<T>> order)
null
or an empty list resets the ordering of all columns.
Columns not mentioned in the list are reset to the unsorted state.
For Grids with multi-sorting, the index of a given column inside the list defines the sort priority. For example, the column at index 0 of the list is sorted first, then on the index 1, and so on.
order
- the list of sort orders to set on the client, or
null
to reset any sort orders.setMultiSort(boolean)
,
getSortOrder()
public List<GridSortOrder<T>> getSortOrder()
protected SerializableComparator<T> createSortingComparator()
public void setHeightByRows(boolean heightByRows)
true
, the grid's height is defined by the number of its
rows. All items are fetched from the DataProvider
, and the Grid
shows no vertical scroll bar.heightByRows
- true
to make Grid compute its height by the
number of rows, false
for the default behavior@Synchronize(value="height-by-rows-changed") public boolean isHeightByRows()
true
if Grid computes its height by the number of
rows, false
otherwisepublic void onEnabledStateChanged(boolean enabled)
Component
By default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.
onEnabledStateChanged
in class Component
enabled
- the new enabled state of the componentpublic Registration addValueProvider(String property, ValueProvider<T,?> valueProvider)
The properties added to by this method are global to the Grid - they can be used in any column.
ValueProviders are registered as DataGenerator
s in the Grid. See
addDataGenerator(DataGenerator)
.
property
- the property name used in the template. For example, in a
template the uses [[item.name]]
, the property is
name
. Not null
valueProvider
- the provider for values for the property, not
null
public Registration addDataGenerator(DataGenerator<T> dataGenerator)
HasDataGenerators
addDataGenerator
in interface HasDataGenerators<T>
dataGenerator
- the data generator to addpublic void removeDataGenerator(DataGenerator<T> dataGenerator)
HasDataGenerators
removeDataGenerator
in interface HasDataGenerators<T>
dataGenerator
- the data generator to removepublic PropertySet<T> getPropertySet()
PropertySet
of bean this Grid is constructed with via
Grid(Class)
. Or null if not constructed from a bean type.PropertySet
of bean this Grid is constructed withpublic Registration addItemClickListener(ComponentEventListener<ItemClickEvent<T>> listener)
listener
- the listener to add, not null
addItemDoubleClickListener(ComponentEventListener)
public Registration addItemDoubleClickListener(ComponentEventListener<ItemDoubleClickEvent<T>> listener)
Note that double click event happens along with a click event. It means
there is no way to get a double click event only (double click without a
click): a click listener added using
addItemClickListener(ComponentEventListener)
(if any) will also
be notified about a click event once a double click event is fired.
Double click event type is not fully supported by the mobile browsers which means that double click event might not work (double click listeners won't be notified) for such browsers.
listener
- the listener to add, not null
addItemClickListener(ComponentEventListener)
public void setVerticalScrollingEnabled(boolean enabled)
enabled
- true
to enable vertical scrolling,
false
to disabled itpublic boolean isVerticalScrollingEnabled()
true
if the vertical scrolling is enabled,
false
otherwisepublic Editor<T> getEditor()
The editor is created using createEditor()
.
createEditor()
public void 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.Column.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.Column.setClassNameGenerator(SerializableFunction)
public SerializableFunction<T,String> getClassNameGenerator()
protected Editor<T> createEditor()
Grid.AbstractGridExtension
, it will be
automatically added to DataCommunicator
.protected ValueProvider<T,String> getUniqueKeyProvider()
protected void setUniqueKeyProvider(ValueProvider<T,String> uniqueKeyProvider)
null
by default.
uniqueKeyProvider
- ValueProvider for unique key for rowprotected String getUniqueKeyProperty()
protected void setUniqueKeyProperty(String uniqueKeyProperty)
uniqueKeyProperty
- the new optional property name for unique keyprotected GridArrayUpdater getArrayUpdater()
protected void onDataProviderChange()
DataChangeEvent
event is
fired).
Default implementation closes the editor if it's opened.Copyright © 2019. All rights reserved.