T
- the grid bean type@Tag(value="vaadin-grid") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="22.0.21") @NpmPackage(value="@vaadin/grid",version="22.0.21") @NpmPackage(value="@vaadin/vaadin-grid",version="22.0.21") @JsModule(value="@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule(value="@vaadin/grid/src/vaadin-grid.js") @JsModule(value="@vaadin/grid/src/vaadin-grid-column.js") @JsModule(value="@vaadin/grid/src/vaadin-grid-sorter.js") @JsModule(value="@vaadin/checkbox/src/vaadin-checkbox.js") @JsModule(value="@vaadin/polymer-legacy-adapter/template-renderer.js") @JsModule(value="./flow-component-renderer.js") @JsModule(value="./gridConnector.js") public class Grid<T> extends Component implements HasStyle, HasSize, Focusable<Grid<T>>, SortEvent.SortNotifier<Grid<T>,GridSortOrder<T>>, HasTheme, HasDataGenerators<T>, HasListDataView<T,GridListDataView<T>>, HasDataView<T,Void,GridDataView<T>>, HasLazyDataView<T,Void,GridLazyDataView<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.NestedNullBehavior
behavior when parsing nested properties which may contain
null values in the property chain |
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> updateQueueBuilder,
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> updateQueueBuilder,
B dataCommunicatorBuilder)
Creates a new instance, with the specified page size and data
communicator.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addCellFocusListener(ComponentEventListener<CellFocusEvent<T>> listener)
Adds a listener to the grid that will be notified, when a cell has been
focused.
|
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) . |
Registration |
addColumnReorderListener(ComponentEventListener<ColumnReorderEvent<T>> listener)
Adds a column reorder listener to this component.
|
Registration |
addColumnResizeListener(ComponentEventListener<ColumnResizeEvent<T>> listener)
Adds a column resize listener to this component.
|
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.
|
Registration |
addDragEndListener(ComponentEventListener<GridDragEndEvent<T>> listener)
Adds a drag end listener to this component.
|
Registration |
addDragStartListener(ComponentEventListener<GridDragStartEvent<T>> listener)
Adds a drag start listener to this component.
|
Registration |
addDropListener(ComponentEventListener<GridDropEvent<T>> listener)
Adds a drop listener to this component.
|
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) |
void |
configureBeanType(Class<T> beanType,
boolean autoCreateColumns)
Sets the bean type this grid is bound to and optionally adds a set of
columns for each of the bean's properties.
|
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() |
Class<T> |
getBeanType()
Returns the Class of bean this Grid is constructed with via
Grid(Class) . |
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() |
SerializablePredicate<T> |
getDragFilter()
Gets the active drag filter.
|
SerializablePredicate<T> |
getDropFilter()
Gets the active drop filter.
|
GridDropMode |
getDropMode()
Gets the drop mode of this drop target.
|
Editor<T> |
getEditor()
Gets the editor.
|
List<FooterRow> |
getFooterRows()
Gets all of the footer rows in the Grid, in order from top to bottom.
|
GridDataView<T> |
getGenericDataView()
Gets the generic data view for the grid.
|
List<HeaderRow> |
getHeaderRows()
Gets all of the header rows in the Grid, in order from top to bottom.
|
GridLazyDataView<T> |
getLazyDataView()
Gets the lazy data view for the grid.
|
GridListDataView<T> |
getListDataView()
Gets the list data view for the grid.
|
Grid.NestedNullBehavior |
getNestedNullBehavior()
Get the behavior when facing nested
null values. |
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 |
isAllRowsVisible()
Gets whether grid's height is defined by the number of its rows.
|
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()
Deprecated.
since 14.7 - use
isAllRowsVisible() |
boolean |
isMultiSort()
Gets whether multiple column sorting is enabled on the client-side.
|
boolean |
isRowsDraggable()
Gets whether rows of the grid can be dragged.
|
boolean |
isVerticalScrollingEnabled()
Gets whether the vertical scrolling on the Grid web component is enabled.
|
protected void |
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
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). |
protected void |
onDetach(DetachEvent detachEvent)
Called when the component is detached from a UI.
|
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 |
recalculateColumnWidths()
Updates the
width of all columns which have autoWidth set
to true . |
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 |
removeColumns(Grid.Column<T>... columns)
Removes columns from the Grid.
|
void |
removeThemeVariants(GridVariant... variants)
Removes theme variants from the component.
|
void |
scrollToEnd()
Scrolls to the last data row of the grid.
|
void |
scrollToIndex(int rowIndex)
Scrolls to the given row index.
|
void |
scrollToStart()
Scrolls to the beginning of the first data row.
|
void |
select(T item)
This method is a shorthand that delegates to the currently set selection
model.
|
void |
setAllRowsVisible(boolean allRowsVisible)
If
true , the grid's height is defined by its rows. |
void |
setClassNameGenerator(SerializableFunction<T,String> classNameGenerator)
Sets the function that is used for generating CSS class names for all the
cells in the rows in this grid.
|
protected void |
setColumnKey(String key,
Grid.Column column)
Sets a user-defined identifier for given column.
|
void |
setColumnOrder(Grid.Column<T>... columns)
Sets a new column order for the grid.
|
void |
setColumnOrder(List<Grid.Column<T>> columns)
Sets a new column order for the grid.
|
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)
Deprecated.
use instead one of the
setItems methods which provide
access to either GridListDataView or
GridLazyDataView |
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 |
setDragDataGenerator(String type,
SerializableFunction<T,String> dragDataGenerator)
Sets a generator function for customizing drag data.
|
void |
setDragFilter(SerializablePredicate<T> dragFilter)
Sets the drag filter for this drag source.
|
void |
setDropFilter(SerializablePredicate<T> dropFilter)
Sets the drop filter for this drag target.
|
void |
setDropMode(GridDropMode dropMode)
Sets the drop mode of this drop target.
|
void |
setHeightByRows(boolean heightByRows)
Deprecated.
since 14.7 - use
setAllRowsVisible(boolean) |
void |
setItemDetailsRenderer(Renderer<T> renderer)
Set the renderer to use for displaying the item details rows in this
grid.
|
GridLazyDataView<T> |
setItems(BackEndDataProvider<T,Void> dataProvider)
Supply items with a
BackEndDataProvider that lazy loads items
from a backend. |
GridDataView<T> |
setItems(DataProvider<T,Void> dataProvider)
Set a generic data provider for the component to use and returns the base
DataView that provides API to get information on the items. |
GridDataView<T> |
setItems(InMemoryDataProvider<T> inMemoryDataProvider)
Sets an in-memory data provider for the component to use
|
GridListDataView<T> |
setItems(ListDataProvider<T> dataProvider)
Sets a ListDataProvider for the component to use and returns a
ListDataView that provides information and allows operations on
the items. |
void |
setItems(Stream<T> streamOfItems)
Deprecated.
Because the stream is collected to a list anyway, use
HasListDataView.setItems(Collection) or
HasLazyDataView.setItems(CallbackDataProvider.FetchCallback)
instead. |
void |
setMultiSort(boolean multiSort)
Sets whether multiple column sorting is enabled on the client-side.
|
void |
setNestedNullBehavior(Grid.NestedNullBehavior nestedNullBehavior)
Set the behavior when facing nested
null values. |
void |
setPageSize(int pageSize)
Sets the page size, which is the number of items fetched at a time from
the data provider.
|
void |
setRowsDraggable(boolean rowsDraggable)
Sets whether the user can drag the grid rows or not.
|
void |
setSelectionDragDetails(int draggedItemsCount,
Map<String,String> dragData)
Sets explicit drag operation details for when the user is dragging the
selected items.
|
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, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
isEnabled, setEnabled
getElement
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
setItems, setItems
setItems, setItems
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> updateQueueBuilder, 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
updateQueueBuilder
- 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> updateQueueBuilder, 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.updateQueueBuilder
- 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 layer@Deprecated public void setDataProvider(DataProvider<T,?> dataProvider)
setItems
methods which provide
access to either GridListDataView
or
GridLazyDataView
@Deprecated public void setItems(Stream<T> streamOfItems)
HasListDataView.setItems(Collection)
or
HasLazyDataView.setItems(CallbackDataProvider.FetchCallback)
instead.public DataProvider<T,?> getDataProvider()
To get information and control over the items in the grid, use either
getListDataView()
or getLazyDataView()
instead.
null
public GridDataView<T> setItems(DataProvider<T,Void> dataProvider)
HasDataView
DataView
that provides API to get information on the items.
This method should be used only when the data provider type is not either
ListDataProvider
or BackEndDataProvider
.
setItems
in interface HasDataView<T,Void,GridDataView<T>>
dataProvider
- DataProvider instance to use, not null
public GridDataView<T> setItems(InMemoryDataProvider<T> inMemoryDataProvider)
HasDataView
Note! Using a ListDataProvider
instead of a
InMemoryDataProvider
is recommended to get access to
ListDataView
API by using
HasListDataView.setItems(ListDataProvider)
.
setItems
in interface HasDataView<T,Void,GridDataView<T>>
inMemoryDataProvider
- InMemoryDataProvider to use, not null
public GridDataView<T> getGenericDataView()
getListDataView()
or getLazyDataView()
is not
applicable for the underlying data provider.getGenericDataView
in interface HasDataView<T,Void,GridDataView<T>>
DataView
implementation for gridgetListDataView()
,
getLazyDataView()
public GridListDataView<T> setItems(ListDataProvider<T> dataProvider)
HasListDataView
ListDataView
that provides information and allows operations on
the items.setItems
in interface HasListDataView<T,GridListDataView<T>>
dataProvider
- ListDataProvider providing items to the component.public GridListDataView<T> getListDataView()
getLazyDataView()
instead.getListDataView
in interface HasListDataView<T,GridListDataView<T>>
public GridLazyDataView<T> setItems(BackEndDataProvider<T,Void> dataProvider)
HasLazyDataView
BackEndDataProvider
that lazy loads items
from a backend. Note that component will query the data provider for the
item count. In case that is not desired for performance reasons, use
HasLazyDataView.setItems(CallbackDataProvider.FetchCallback)
instead.
The returned data view object can be used for further configuration, or
later on fetched with HasLazyDataView.getLazyDataView()
. For using in-memory
data, like Collection
, use
HasListDataView.setItems(Collection)
instead.
setItems
in interface HasLazyDataView<T,Void,GridLazyDataView<T>>
dataProvider
- BackEndDataProvider instancepublic GridLazyDataView<T> getLazyDataView()
HasLazyDataView.setItems(CallbackDataProvider.FetchCallback)
HasLazyDataView.setItems(CallbackDataProvider.FetchCallback, CallbackDataProvider.CountCallback)
setItems(BackEndDataProvider)
getListDataView()
instead.getLazyDataView
in interface HasLazyDataView<T,Void,GridLazyDataView<T>>
public DataCommunicator<T> getDataCommunicator()
null
public int getPageSize()
public void setPageSize(int pageSize)
50
, the grid might
fetch items for example as: 0-49, 50-149, 150-200...
.
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.
With automatically extending grid, controlling the item count and how
much it is increased when scrolling is possible via
getLazyDataView()
.
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 select, not nullgetSelectionModel()
,
GridSelectionModel
public void deselect(T item)
item
- the item to deselect, not nullgetSelectionModel()
,
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
NullPointerException
- if the column is null
IllegalArgumentException
- if the column is not owned by this Gridpublic void removeColumns(Grid.Column<T>... columns)
columns
- the columns to be removed, not null
NullPointerException
- if the column is null
IllegalArgumentException
- if the column is not owned by 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()
protected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
protected void onDetach(DetachEvent detachEvent)
Component
The default implementation does nothing.
This method is invoked before the DetachEvent
is fired for the
component.
public List<GridSortOrder<T>> getSortOrder()
protected SerializableComparator<T> createSortingComparator()
@Deprecated public void setHeightByRows(boolean heightByRows)
setAllRowsVisible(boolean)
true
, the grid's height is defined by its rows. All items
are fetched from the DataProvider
, and the Grid shows no vertical
scroll bar.
Note: setHeightByRows
disables the grid's virtual scrolling
so that all the rows are rendered in the DOM at once. If the grid has a
large number of items, using the feature is discouraged to avoid
performance issues.
heightByRows
- true
to make Grid compute its height by the
number of rows, false
for the default behaviorsetAllRowsVisible(boolean)
@Deprecated public boolean isHeightByRows()
isAllRowsVisible()
true
if Grid computes its height by the number of
rows, false
otherwiseisAllRowsVisible()
public void setAllRowsVisible(boolean allRowsVisible)
true
, the grid's height is defined by its rows. All items
are fetched from the DataProvider
, and the Grid shows no vertical
scroll bar.
Note: setAllRowsVisible
disables the grid's virtual
scrolling so that all the rows are rendered in the DOM at once. If the
grid has a large number of items, using the feature is discouraged to
avoid performance issues.
allRowsVisible
- true
to make Grid compute its height by the
number of rows, false
for the default behavior@Synchronize(value="all-rows-visible-changed") public boolean isAllRowsVisible()
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 configureBeanType(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"
.
This method can only be called for a newly instanced Grid without any beanType or columns set.
beanType
- the bean type to use, not null
autoCreateColumns
- when true
, columns are created automatically for
the properties of the beanTypepublic Class<T> getBeanType()
Grid(Class)
. Or null if not constructed from a bean type.public 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 addColumnResizeListener(ComponentEventListener<ColumnResizeEvent<T>> listener)
listener
- the listener to add, not null
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 Registration addCellFocusListener(ComponentEventListener<CellFocusEvent<T>> listener)
listener
- the listener to add, not null
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 void recalculateColumnWidths()
width
of all columns which have autoWidth
set
to true
.Grid.Column.setAutoWidth(boolean)
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.public Registration addDropListener(ComponentEventListener<GridDropEvent<T>> listener)
listener
- the listener to add, not null
public Registration addDragStartListener(ComponentEventListener<GridDragStartEvent<T>> listener)
listener
- the listener to add, not null
public Registration addDragEndListener(ComponentEventListener<GridDragEndEvent<T>> listener)
listener
- the listener to add, not null
public void setDropMode(GridDropMode dropMode)
null
,
grid fires drop events upon data drop over the grid or the grid rows.
When using GridDropMode.ON_TOP
, and the grid is either empty or
has empty space after the last row, the drop can still happen on the
empty space, and the GridDropEvent.getDropTargetItem()
will
return an empty optional.
When using GridDropMode.BETWEEN
or
GridDropMode.ON_TOP_OR_BETWEEN
, and there is at least one row in
the grid, any drop after the last row in the grid will get the last row
as the GridDropEvent.getDropTargetItem()
. If there are no rows in
the grid, then it will return an empty optional.
If using GridDropMode.ON_GRID
, then the drop will not happen on
any row, but instead just "on the grid". The target row will not be
present in this case.
NOTE: Prefer not using a row specific GridDropMode
with a
grid that enables sorting. If for example a new row gets added to a
specific location on drop event, it might not end up in the location of
the drop but rather where the active sorting configuration prefers to
place it. This behavior might feel unexpected for the users.
dropMode
- Drop mode that describes the allowed drop locations within the
Grid's row. Can be null
to disable dropping on the
grid.GridDropEvent.getDropLocation()
public GridDropMode getDropMode()
null
if dropping is not enabled.public void setRowsDraggable(boolean rowsDraggable)
rowsDraggable
- true
if the rows can be dragged by the user;
false
if notpublic boolean isRowsDraggable()
true
if the rows are draggable, false
otherwisepublic SerializablePredicate<T> getDropFilter()
public SerializablePredicate<T> getDragFilter()
public void setDropFilter(SerializablePredicate<T> dropFilter)
When the drop mode of the grid has been set to one of
GridDropMode.BETWEEN
, GridDropMode.ON_TOP
or
GridDropMode.ON_TOP_OR_BETWEEN
, by default all the visible rows
can be dropped over.
A drop filter function can be used to specify the rows that are available
for dropping over. The function receives an item and should return
true
if the row can be dropped over, false
otherwise.
NOTE: If the filter conditions depend on a specific row that's
currently being dragged, you might want to have the grid's drop mode
disabled by default and set its value only on drag start to avoid the
small period of time during which the user might be able to drop over
unwanted rows. Once the drop end event occurs, the drop mode can be set
back to
NOTE: If the filtering conditions change dynamically, remember to
explicitly invoke null
to keep this consistent.
getDataProvider().refreshItem(item)
for the
relevant items to get the filters re-run for them.
public void setDragFilter(SerializablePredicate<T> dragFilter)
When the setRowsDraggable(boolean)
has been used to enable
dragging, by default all the visible rows can be dragged.
A drag filter function can be used to specify the rows that are available
for dragging. The function receives an item and returns true
if
the row can be dragged, false
otherwise.
NOTE: If the filtering conditions change dynamically, remember to
explicitly invoke getDataProvider().refreshItem(item)
for the
relevant items to get the filters re-run for them.
public void setDragDataGenerator(String type, SerializableFunction<T,String> dragDataGenerator)
type
as the generator is set
here. The function is executed for each item in the Grid during data
generation. Return a String
to be appended to the row as type
data.
Note that IE11 only supports data type "text"
type
- Type of the generated data. The generated value will be
accessible during drop using this type.dragDataGenerator
- Function to be executed on row data generation.public void setSelectionDragDetails(int draggedItemsCount, Map<String,String> dragData)
Note that IE11 only supports data type "text"
draggedItemsCount
- The number shown in the drag image on selection drag. Only
values above 1 have any visible effect.dragData
- The drag data for selection drag. The map should consist of
data type:data -entriespublic Registration addColumnReorderListener(ComponentEventListener<ColumnReorderEvent<T>> listener)
listener
- the listener to add, not null
public void setColumnOrder(Grid.Column<T>... columns)
The function doesn't support column removal: all columns must be present
in the list, otherwise IllegalArgumentException
is thrown.
The getColumns()
function will reflect the new column ordering.
Fires the ColumnReorderEvent
with
ComponentEvent.isFromClient()
returning false
.
The method is atomic: if the requested reordering is not achievable, the
function fails cleanly with IllegalArgumentException
without
doing any work.
columns
- the new ordering of the columns, not null
.NullPointerException
- if the columns
parameter is null
.IllegalArgumentException
- if a column is present two times in the list, or if the
column is not owned by this Grid, or if the list doesn't
contain all columns currently present in the Grid, or if the
column rearranging would require to split a joined
header/footer cell group.setColumnOrder(List)
public void setColumnOrder(List<Grid.Column<T>> columns)
The function doesn't support column removal: all columns must be present
in the list, otherwise IllegalArgumentException
is thrown.
The getColumns()
function will reflect the new column ordering.
Fires the ColumnReorderEvent
with
ComponentEvent.isFromClient()
returning false
.
The method is atomic: if the requested reordering is not achievable, the
function fails cleanly with IllegalArgumentException
without
doing any work.
columns
- the new ordering of the columns, not null
.NullPointerException
- if the columns
parameter is null
.IllegalArgumentException
- if a column is present two times in the list, or if the
column is not owned by this Grid, or if the list doesn't
contain all columns currently present in the Grid, or if the
column rearranging would require to split a joined
header/footer cell group.setColumnOrder(Column[])
public void scrollToIndex(int rowIndex)
rowIndex
- zero based index of the item to scroll to in the current view.public void scrollToStart()
public void scrollToEnd()
public void setNestedNullBehavior(Grid.NestedNullBehavior nestedNullBehavior)
null
values. By default
the value is NestedNullBehavior.THROW
.nestedNullBehavior
- the behavior when facing nested null
values.public Grid.NestedNullBehavior getNestedNullBehavior()
null
values.null
values.Copyright © 2022. All rights reserved.