Class BeanTable<T>
- Type Parameters:
T- Bean type for the Table
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.data.provider.HasDataView<T,,Void, BeanTableDataView<T>> com.vaadin.flow.data.provider.HasLazyDataView<T,,Void, BeanTableLazyDataView<T>> com.vaadin.flow.data.provider.HasListDataView<T,,BeanTableListDataView<T>> Serializable
- Author:
- Tatu Lund
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLocalization object for BeanTableclassConfiguration class for the Columns.static enumstatic enumstatic interfacestatic enumstatic interface -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor.BeanTable(int pageLength) The default constructor with defined page length.Creates a new BeanTable with an initial set of columns for each of the bean's properties.Creates a new BeanTable with an initial set of columns for each of the bean's properties.Creates a new BeanTable with an initial set of columns for each of the bean's properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd column to Table with the given property name.Add a column with a value provider.addComponentColumn(String header, BeanTable.ComponentProvider<T> componentProvider) Add a column with component provider.com.vaadin.flow.shared.RegistrationaddItemClickedListener(com.vaadin.flow.component.ComponentEventListener<ItemClickedEvent<T, BeanTable<T>>> listener) Add ItemClickedEvent listener to the BeanTablecom.vaadin.flow.shared.RegistrationaddSelectionChangedListener(com.vaadin.flow.component.ComponentEventListener<BeanTableSelectionChangedEvent<T, BeanTable<T>>> listener) Add SelectionChangedEvent listener to the BeanTablevoidaddThemeVariants(BeanTableVariant... variants) Adds theme variants to the component.voidDeselect items.voidClear the selection.protected TfetchItem(int index) voidfocus()Push focus to first body cell, not row header cell.voidfocus(int row, int col) Push focus to specific row and column by index if such cell exists in the table.voidPush focus to the first column of the row where item is if item is on the current page.Get the column by its key.Get list of the currently set columns.com.vaadin.flow.data.provider.DataProvider<T, ?> Return the currently used data provider.getI18n()Gets the internationalization object previously set for this component.intgetPage()Get current page.intGet the number of the rows in the table after filtering.Get currently selected items.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) voidremoveThemeVariants(BeanTableVariant... variants) Removes theme variants from the component.voidSelect items.voidsetCaption(String caption) Set the caption associated with the TablevoidsetClassNameProvider(BeanTable.StringProvider<T> classNameProvider) Set class name provider for a table row.voidsetColumns(String... propertyNames) Configure BeanTable to have columns with given set of property names.voidsetColumnSelectionMenu(BeanTable.ColumnSelectMenu columnSelect) Use ColumnSelectMenu.CONTEXT column selection as context menu.voidsetDataProvider(com.vaadin.flow.data.provider.DataProvider<T, ?> dataProvider) Deprecated.voidsetFocusBehavior(BeanTable.FocusBehavior focusBehavior) Set the focus behavior of this table for A11y.voidsetHtmlAllowed(boolean htmlAllowed) Set whether cell content should allow html content or not.voidSets the internationalization properties (texts used for button tooltips) for this component.voidvoidsetPage(int page) Set the currently shown page.voidsetSelectionEnabled(boolean selectionEnabled) Enable/disable selection for user.Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.data.provider.HasLazyDataView
setItems, setItemsMethods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems, setItemsMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
Constructor Details
-
BeanTable
public BeanTable()The default constructor. This creates a BeanTable without further configuration. UseaddColumn(String,ValueProvider)addComponentColumn(String,ComponentProvider)to configure columns. -
BeanTable
public BeanTable(int pageLength) The default constructor with defined page length. Use this constructor with large data sources, i.e. DataProvider.fromCallBacks(..). This constructor enables paging controls in the footer row. Also this creates a BeanTable without further configuration. UseaddColumn(String,ValueProvider)addComponentColumn(String,ComponentProvider)to configure columns.- Parameters:
pageLength- Size of the page
-
BeanTable
Creates a new BeanTable with an initial set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the header captions.- Parameters:
beanType- the bean type to use, notnull
-
BeanTable
Creates a new BeanTable with an initial set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the header captions.Constructor with defined page length. Use this constructor with large data sources, i.e. DataProvider.fromCallBacks(..). This constructor enables paging controls in the footer row.
When autoCreateColumns is
false. UsesetColumns(String...)to define which properties to include and in which order. You can also add a column for an individual property withaddColumn(String).- Parameters:
beanType- the bean type to use, notnullautoCreateColumns- whentrue, columns are created automatically for the properties of the beanType
-
BeanTable
Creates a new BeanTable with an initial set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the header captions.When autoCreateColumns is
false. UsesetColumns(String...)to define which properties to include and in which order. You can also add a column for an individual property withaddColumn(String).- Parameters:
beanType- the bean type to use, notnullautoCreateColumns- whentrue, columns are created automatically for the properties of the beanTypepageLength- Size of the page
-
-
Method Details
-
addColumn
Add column to Table with the given property name.- Parameters:
propertyName- The property
-
setColumns
Configure BeanTable to have columns with given set of property names.- Parameters:
propertyNames- List of property names
-
addColumn
public BeanTable<T>.Column<T> addColumn(String header, com.vaadin.flow.function.ValueProvider<T, ?> valueProvider) Add a column with a value provider. Value provider is a function reference, e.g. getter of the bean or lambda that returns the value for this column.- Parameters:
header- The header as a string, can be nullvalueProvider- The value provider- Returns:
- A column
-
addComponentColumn
public BeanTable<T>.Column<T> addComponentColumn(String header, BeanTable.ComponentProvider<T> componentProvider) Add a column with component provider. Component provider is a lambda that must return a new instance of a component.- Parameters:
header- Header as string, can be nullcomponentProvider- Component provider- Returns:
- A column
-
setDataProvider
@Deprecated public void setDataProvider(com.vaadin.flow.data.provider.DataProvider<T, ?> dataProvider) Deprecated. -
fetchItem
-
getDataProvider
Return the currently used data provider.- Returns:
- A data provider
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
setHtmlAllowed
public void setHtmlAllowed(boolean htmlAllowed) Set whether cell content should allow html content or not. If this is false (default), value will be set as text content of the cell. If set to true the value string will be wrapped in span element and can contain html.- Parameters:
htmlAllowed- A boolean value.
-
setClassNameProvider
Set class name provider for a table row.- Parameters:
classNameProvider- StringProvider Lambda callback bean instance to String.
-
getClassNameProvider
-
getGenericDataView
- Specified by:
getGenericDataViewin interfacecom.vaadin.flow.data.provider.HasDataView<T,Void, BeanTableDataView<T>>
-
setItems
public BeanTableDataView<T> setItems(com.vaadin.flow.data.provider.DataProvider<T, Void> dataProvider) - Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasDataView<T,Void, BeanTableDataView<T>>
-
setItems
public BeanTableDataView<T> setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider) - Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasDataView<T,Void, BeanTableDataView<T>>
-
getListDataView
- Specified by:
getListDataViewin interfacecom.vaadin.flow.data.provider.HasListDataView<T,BeanTableListDataView<T>>
-
setItems
public BeanTableListDataView<T> setItems(com.vaadin.flow.data.provider.ListDataProvider<T> dataProvider) - Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasListDataView<T,BeanTableListDataView<T>>
-
setItems
-
setItems
public BeanTableLazyDataView<T> setItems(com.vaadin.flow.data.provider.BackEndDataProvider<T, Void> dataProvider) - Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasLazyDataView<T,Void, BeanTableLazyDataView<T>>
-
getLazyDataView
- Specified by:
getLazyDataViewin interfacecom.vaadin.flow.data.provider.HasLazyDataView<T,Void, BeanTableLazyDataView<T>>
-
getColumns
Get list of the currently set columns.- Returns:
- List of Columns
-
getColumn
Get the column by its key.- Parameters:
key- The key, can't be null- Returns:
- Optional Column
-
setCaption
Set the caption associated with the Table- Parameters:
caption- A string value. Null will remove caption.
-
setPage
public void setPage(int page) Set the currently shown page.- Parameters:
page- int value base 0- Throws:
IllegalArgumentException- if BeanTable is not in paged mode or page is not in acceptable range.
-
getPage
public int getPage()Get current page.- Returns:
- int value base 0, or -1 if BeanTable is not paged mode.
-
getRowCount
public int getRowCount()Get the number of the rows in the table after filtering.- Returns:
- int value.
-
setI18n
Sets the internationalization properties (texts used for button tooltips) for this component.- Parameters:
i18n- the internationalized properties, null to disable all tooltips.
-
getI18n
Gets the internationalization object previously set for this component.- Returns:
- the i18n object. It will be
null, If the i18n properties weren't set.
-
focus
public void focus()Push focus to first body cell, not row header cell.Note: If FocusBehavior.NONE used, then does nothing.
-
focus
Push focus to the first column of the row where item is if item is on the current page.Note: If FocusBehavior.NONE used, then does nothing.
- Parameters:
item- The item to focus.
-
focus
public void focus(int row, int col) Push focus to specific row and column by index if such cell exists in the table.Note: If FocusBehavior.NONE used, then does nothing.
- Parameters:
row- int valuecol- int value
-
setFocusBehavior
Set the focus behavior of this table for A11y. NONE is the default and table is skipped in focus tabbing. When BODY is used only body cells gets focus. When BODY_AND_HEADER is used also header cells get focus.- Parameters:
focusBehavior- FocusBehavior
-
addThemeVariants
Adds theme variants to the component.- Parameters:
variants- theme variants to add
-
removeThemeVariants
Removes theme variants from the component.- Parameters:
variants- theme variants to remove
-
setColumnSelectionMenu
Use ColumnSelectMenu.CONTEXT column selection as context menu. Use ColumnSelectMenu.BUTTON to column selection button to open the menu in the last header cell.- Parameters:
columnSelect- ColumnSelectMenu
-
getSelected
Get currently selected items.- Returns:
- Set of selected items.
-
select
Select items.- Parameters:
items- Items to be selected.
-
deselect
Deselect items.- Parameters:
items- Items to be deselected.
-
deselectAll
public void deselectAll()Clear the selection. -
setSelectionEnabled
public void setSelectionEnabled(boolean selectionEnabled) Enable/disable selection for user.Note: If turned on, FocusBehavior is set to FocusBehavior.BODY_AND_HEADER to allow keyboard controls.
- Parameters:
selectionEnabled- Boolean value.
-
addSelectionChangedListener
public com.vaadin.flow.shared.Registration addSelectionChangedListener(com.vaadin.flow.component.ComponentEventListener<BeanTableSelectionChangedEvent<T, BeanTable<T>>> listener) Add SelectionChangedEvent listener to the BeanTable- Parameters:
listener- the listener to add.- Returns:
- a registration for the listener
-
addItemClickedListener
public com.vaadin.flow.shared.Registration addItemClickedListener(com.vaadin.flow.component.ComponentEventListener<ItemClickedEvent<T, BeanTable<T>>> listener) Add ItemClickedEvent listener to the BeanTable- Parameters:
listener- the listener to add.- Returns:
- a registration for the listener
-