Class GridHelper<T>
- java.lang.Object
-
- com.flowingcode.vaadin.addons.gridhelpers.GridHelper<T>
-
- All Implemented Interfaces:
java.io.Serializable
@JsModule("./fcGridHelper/connector.js") @CssImport(value="./fcGridHelper/vaadin-menu-bar.css",themeFor="vaadin-menu-bar") @CssImport(value="./fcGridHelper/vaadin-grid.css",themeFor="vaadin-grid") @CssImport(value="./fcGridHelper/vaadin-context-menu-item.css",themeFor="vaadin-context-menu-item") @CssImport(value="./fcGridHelper/vaadin-context-menu-list-box.css",themeFor="vaadin-context-menu-list-box") @CssImport(value="./fcGridHelper/vaadin-menu-bar-item.css",themeFor="vaadin-menu-bar-item") @CssImport(value="./fcGridHelper/vaadin-menu-bar-list-box.css",themeFor="vaadin-menu-bar-list-box") @CssImport(value="./fcGridHelper/vaadin-checkbox.css",themeFor="vaadin-checkbox") public final class GridHelper<T> extends java.lang.Object implements java.io.Serializable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DENSE_THEME
Compact row styling for Vaadin Gridstatic java.lang.String
GRID_STYLES
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> CheckboxColumn<T>
addCheckboxColumn(com.vaadin.flow.component.grid.Grid<T> grid, CheckboxColumn.CheckboxColumnConfiguration<T> config)
static <T> com.vaadin.flow.shared.Registration
addColumnToggleListener(com.vaadin.flow.component.grid.Grid<T> grid, com.vaadin.flow.component.ComponentEventListener<ColumnToggleEvent<T>> listener)
Adds a listener that is notified when column visibility is modified through the sidebar menu.static void
addToolbarFooter(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.Component toolBar)
static com.vaadin.flow.component.Component
getEmptyGridLabel(com.vaadin.flow.component.grid.Grid<?> grid)
Returns the component that is displayed when the Grid would show an empty data set.static java.lang.String
getFooter(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.Grid.Column<?> column)
Deprecated.static GridStylesHelper
getFooterStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.FooterRow row)
static GridStylesHelper
getFooterStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.FooterRow.FooterCell cell)
static java.lang.String
getHeader(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.Grid.Column<?> column)
Deprecated.static GridStylesHelper
getHeaderStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.HeaderRow row)
static GridStylesHelper
getHeaderStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.HeaderRow.HeaderCell cell)
static double
getHeightByRows(com.vaadin.flow.component.grid.Grid<?> grid)
Gets the amount of rows in Grid's body that are shown, while#getHeightMode()
isHeightMode.ROW
.static HeightMode
getHeightMode(com.vaadin.flow.component.grid.Grid<?> grid)
Defines the mode in which the Grid's height is calculated.static <T> java.lang.String
getHidingToggleCaption(com.vaadin.flow.component.grid.Grid.Column<T> column)
Returns the caption of the hiding toggle for this column.static <T> java.util.Collection<GridResponsiveStep<T>>
getResponsiveSteps(com.vaadin.flow.component.grid.Grid<T> grid)
Return the responsive steps of the givengrid
.static <T> com.vaadin.flow.function.SerializablePredicate<T>
getSelectionFilter(com.vaadin.flow.component.grid.Grid<T> grid)
Returns the predicate for determining which rows are selectable.static com.vaadin.flow.component.grid.Grid.SelectionMode
getSelectionMode(com.vaadin.flow.component.grid.Grid<?> grid)
Return the grid selection modestatic boolean
isArrowSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether Grid rows can be selected using up/down arrow keys.static boolean
isColumnToggleVisible(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether the menu to toggle the visibility of grid columns is visible.static boolean
isEnhancedSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether the enhanced selection is enabled.static boolean
isFooterVisible(com.vaadin.flow.component.grid.Grid<?> grid)
Returns the visibility of the footer section.static boolean
isHeaderVisible(com.vaadin.flow.component.grid.Grid<?> grid)
Returns the visibility of the header section.static <T> boolean
isHidable(com.vaadin.flow.component.grid.Grid.Column<T> column)
Returns whether this column can be hidden by the user.static boolean
isMenuToggleColumn(com.vaadin.flow.component.grid.Grid.Column<?> column)
static boolean
isSelectionColumnFrozen(com.vaadin.flow.component.grid.Grid<?> grid)
Deprecated.static boolean
isSelectionColumnHidden(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether the multiselect selection column is hidden.static boolean
isSelectOnClick(com.vaadin.flow.component.grid.Grid<?> grid)
static <T> GridResponsiveStep<T>
responsiveStep(com.vaadin.flow.component.grid.Grid<T> grid, int minWidth)
Get or create a responsive steps for the givengrid
and minimum width.static void
setArrowSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid, boolean value)
Allows Grid rows to be selected using up/down arrow keys.void
setClassNameGenerator(com.vaadin.flow.function.SerializableFunction<T,java.lang.String> classNameGenerator)
Sets the function that is used for generating CSS class names for all the cells in the rows in this grid.static void
setColumnToggleVisible(com.vaadin.flow.component.grid.Grid<?> grid, boolean visible)
Shows a menu to toggle the visibility of grid columns.static void
setEmptyGridLabel(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.Component component)
Sets a component that is displayed when the Grid would show an empty data set.static void
setEnhancedSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid, boolean enabled)
When enabled, enhances grid row selection support adding support for these combinations: click, arrow up/down, shift+click, shift+arrow up/down, ctrl+click and ctrl+space.static void
setFooterVisible(com.vaadin.flow.component.grid.Grid<?> grid, boolean visible)
Sets the visibility of the footer section.static void
setHeaderVisible(com.vaadin.flow.component.grid.Grid<?> grid, boolean visible)
static void
setHeightByRows(com.vaadin.flow.component.grid.Grid<?> grid, double rows)
Sets the number of rows that should be visible in Grid's body, while#getHeightMode()
isHeightMode.ROW
.static void
setHeightByRows(com.vaadin.flow.component.grid.Grid<?> grid, int rows)
Sets the number of rows that should be visible in Grid's body, while#getHeightMode()
isHeightMode.ROW
.static void
setHeightMode(com.vaadin.flow.component.grid.Grid<?> grid, HeightMode heightMode)
Defines the mode in which the Grid's height is calculated.protected void
setHelperClassNameGenerator(java.lang.Class<?> clazz, com.vaadin.flow.function.SerializableFunction<T,java.lang.String> generator)
static <T> com.vaadin.flow.component.grid.Grid.Column<T>
setHidable(com.vaadin.flow.component.grid.Grid.Column<T> column, boolean hidable)
Sets whether this column can be hidden by the user.static <T> void
setHidingToggleCaption(com.vaadin.flow.component.grid.Grid.Column<T> column, java.lang.String caption)
Sets the caption of the hiding toggle for this column.static void
setSelectionColumnFrozen(com.vaadin.flow.component.grid.Grid<?> grid, boolean value)
Deprecated.static void
setSelectionColumnHidden(com.vaadin.flow.component.grid.Grid<?> grid, boolean value)
Sets whether the multiselect selection column is hidden.static <T> void
setSelectionFilter(com.vaadin.flow.component.grid.Grid<T> grid, com.vaadin.flow.function.SerializablePredicate<T> predicate)
Sets a predicate for determining which rows are selectable.static void
setSelectOnClick(com.vaadin.flow.component.grid.Grid<?> grid, boolean selectOnClick)
static <T> GridRadioSelectionColumn
showRadioSelectionColumn(com.vaadin.flow.component.grid.Grid<T> grid)
static <T> void
toggleSelectAllCheckbox(com.vaadin.flow.component.grid.Grid<T> grid, boolean visible)
Toggles select all checkbox visibility in the grid's default header row for the selection column.
-
-
-
Field Detail
-
GRID_STYLES
public static final java.lang.String GRID_STYLES
- See Also:
- Constant Field Values
-
DENSE_THEME
public static final java.lang.String DENSE_THEME
Compact row styling for Vaadin Grid- See Also:
- Constant Field Values
-
-
Method Detail
-
setHelperClassNameGenerator
protected void setHelperClassNameGenerator(java.lang.Class<?> clazz, com.vaadin.flow.function.SerializableFunction<T,java.lang.String> generator)
-
getSelectionMode
public static com.vaadin.flow.component.grid.Grid.SelectionMode getSelectionMode(com.vaadin.flow.component.grid.Grid<?> grid)
Return the grid selection mode
-
setClassNameGenerator
public void setClassNameGenerator(com.vaadin.flow.function.SerializableFunction<T,java.lang.String> classNameGenerator)
Sets the function that is used for generating CSS class names for all the cells in the rows in this grid. Returningnull
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.- Parameters:
classNameGenerator
- the class name generator to set, notnull
- Throws:
java.lang.NullPointerException
- ifclassNameGenerator
isnull
- See Also:
Grid.Column.setClassNameGenerator(SerializableFunction)
-
setSelectOnClick
public static void setSelectOnClick(com.vaadin.flow.component.grid.Grid<?> grid, boolean selectOnClick)
-
isSelectOnClick
public static boolean isSelectOnClick(com.vaadin.flow.component.grid.Grid<?> grid)
-
setArrowSelectionEnabled
public static void setArrowSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid, boolean value)
Allows Grid rows to be selected using up/down arrow keys.
-
isArrowSelectionEnabled
public static boolean isArrowSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether Grid rows can be selected using up/down arrow keys.
-
setSelectionColumnHidden
public static void setSelectionColumnHidden(com.vaadin.flow.component.grid.Grid<?> grid, boolean value)
Sets whether the multiselect selection column is hidden.
-
setSelectionColumnFrozen
@Deprecated public static void setSelectionColumnFrozen(com.vaadin.flow.component.grid.Grid<?> grid, boolean value)
Deprecated.Sets whether the multiselect selection column is frozen.
-
isSelectionColumnHidden
public static boolean isSelectionColumnHidden(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether the multiselect selection column is hidden.
-
isSelectionColumnFrozen
@Deprecated public static boolean isSelectionColumnFrozen(com.vaadin.flow.component.grid.Grid<?> grid)
Deprecated.Returns whether the multiselect selection column is frozen.
-
setSelectionFilter
public static <T> void setSelectionFilter(com.vaadin.flow.component.grid.Grid<T> grid, com.vaadin.flow.function.SerializablePredicate<T> predicate)
Sets a predicate for determining which rows are selectable.After a call to
Grid.setSelectionMode(SelectionMode)
the selection filter is lost and it has to be configured again:GridHelper.setSelectionFilter(grid, GridHelper.getSelectionFilter(grid)); // static call grid.setSelectionFilter(grid.getSelectionFilter()); // with lombok extension
-
getSelectionFilter
public static <T> com.vaadin.flow.function.SerializablePredicate<T> getSelectionFilter(com.vaadin.flow.component.grid.Grid<T> grid)
Returns the predicate for determining which rows are selectable.
-
setColumnToggleVisible
public static void setColumnToggleVisible(com.vaadin.flow.component.grid.Grid<?> grid, boolean visible)
Shows a menu to toggle the visibility of grid columns.
-
isColumnToggleVisible
public static boolean isColumnToggleVisible(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether the menu to toggle the visibility of grid columns is visible.
-
isHidable
public static <T> boolean isHidable(com.vaadin.flow.component.grid.Grid.Column<T> column)
Returns whether this column can be hidden by the user. Default isfalse
.- Returns:
true
if the user can hide the column,false
if not.
-
setHidable
public static <T> com.vaadin.flow.component.grid.Grid.Column<T> setHidable(com.vaadin.flow.component.grid.Grid.Column<T> column, boolean hidable)
Sets whether this column can be hidden by the user. Hidable columns can be hidden and shown via the sidebar menu.- Parameters:
column
- the column to be configuredhidable
-true
if the column may be hidden by the user via UI interaction- Returns:
- the column.
-
addColumnToggleListener
public static <T> com.vaadin.flow.shared.Registration addColumnToggleListener(com.vaadin.flow.component.grid.Grid<T> grid, com.vaadin.flow.component.ComponentEventListener<ColumnToggleEvent<T>> listener)
Adds a listener that is notified when column visibility is modified through the sidebar menu.
-
setHidingToggleCaption
public static <T> void setHidingToggleCaption(com.vaadin.flow.component.grid.Grid.Column<T> column, java.lang.String caption)
Sets the caption of the hiding toggle for this column. Shown in the toggle for this column in the grid's sidebar when the column is hidable.If the value is
null
, the column cannot be hidden via the sidebar menu.- Parameters:
hidingToggleCaption
- the text to show in the column hiding toggle
-
getHidingToggleCaption
public static <T> java.lang.String getHidingToggleCaption(com.vaadin.flow.component.grid.Grid.Column<T> column)
Returns the caption of the hiding toggle for this column.- Returns:
- the text shown in the column hiding toggle
-
isMenuToggleColumn
public static boolean isMenuToggleColumn(com.vaadin.flow.component.grid.Grid.Column<?> column)
-
setEmptyGridLabel
public static void setEmptyGridLabel(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.Component component)
Sets a component that is displayed when the Grid would show an empty data set.
-
getEmptyGridLabel
public static com.vaadin.flow.component.Component getEmptyGridLabel(com.vaadin.flow.component.grid.Grid<?> grid)
Returns the component that is displayed when the Grid would show an empty data set.
-
addToolbarFooter
public static void addToolbarFooter(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.Component toolBar)
-
getHeader
@Deprecated public static java.lang.String getHeader(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.Grid.Column<?> column)
Deprecated.
-
getFooter
@Deprecated public static java.lang.String getFooter(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.Grid.Column<?> column)
Deprecated.
-
setEnhancedSelectionEnabled
public static final void setEnhancedSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid, boolean enabled)
When enabled, enhances grid row selection support adding support for these combinations: click, arrow up/down, shift+click, shift+arrow up/down, ctrl+click and ctrl+space.- Parameters:
grid
-enabled
-
-
isEnhancedSelectionEnabled
public static boolean isEnhancedSelectionEnabled(com.vaadin.flow.component.grid.Grid<?> grid)
Returns whether the enhanced selection is enabled.
-
setHeaderVisible
public static void setHeaderVisible(com.vaadin.flow.component.grid.Grid<?> grid, boolean visible)
-
isHeaderVisible
public static boolean isHeaderVisible(com.vaadin.flow.component.grid.Grid<?> grid)
Returns the visibility of the header section.- Returns:
- true if visible, false otherwise.
-
setFooterVisible
public static void setFooterVisible(com.vaadin.flow.component.grid.Grid<?> grid, boolean visible)
Sets the visibility of the footer section.- Parameters:
visible
- true to show footer section, false to hide
-
isFooterVisible
public static boolean isFooterVisible(com.vaadin.flow.component.grid.Grid<?> grid)
Returns the visibility of the footer section.- Returns:
- true if visible, false otherwise.
-
getHeaderStyles
public static GridStylesHelper getHeaderStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.HeaderRow row)
-
getFooterStyles
public static GridStylesHelper getFooterStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.FooterRow row)
-
getHeaderStyles
public static GridStylesHelper getHeaderStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.HeaderRow.HeaderCell cell)
-
getFooterStyles
public static GridStylesHelper getFooterStyles(com.vaadin.flow.component.grid.Grid<?> grid, com.vaadin.flow.component.grid.FooterRow.FooterCell cell)
-
setHeightByRows
public static void setHeightByRows(com.vaadin.flow.component.grid.Grid<?> grid, double rows)
Sets the number of rows that should be visible in Grid's body, while#getHeightMode()
isHeightMode.ROW
.The algorithm assumes that all data rows have the same height and considers headers, footers, and the horizontal scrollbar when the method is called. However, if data rows, headers, or footers are inserted or removed after the initial calculation, the grid may not automatically adjust the size of the grid to accommodate the changed number of rows.
- Parameters:
rows
- The height in terms of number of rows displayed in Grid's body. If Grid doesn't contain enough rows, white space is displayed instead.- Throws:
java.lang.IllegalArgumentException
- ifrows
is zero or lessjava.lang.IllegalArgumentException
- ifrows
isinfinite
java.lang.IllegalArgumentException
- ifrows
isNaN
-
setHeightByRows
public static void setHeightByRows(com.vaadin.flow.component.grid.Grid<?> grid, int rows)
Sets the number of rows that should be visible in Grid's body, while#getHeightMode()
isHeightMode.ROW
.If Grid is currently not in
HeightMode.ROW
, the given value is remembered, and applied once the mode is applied. @SeesetHeightByRows(Grid, double)
-
getHeightByRows
public static double getHeightByRows(com.vaadin.flow.component.grid.Grid<?> grid)
Gets the amount of rows in Grid's body that are shown, while#getHeightMode()
isHeightMode.ROW
.- Returns:
- the amount of rows that are being shown in Grid's body
- See Also:
#setHeightByRows(double)
-
setHeightMode
public static void setHeightMode(com.vaadin.flow.component.grid.Grid<?> grid, HeightMode heightMode)
Defines the mode in which the Grid's height is calculated.If
HeightMode.CSS
is given, Grid will respect the values given via asetHeight
-method, and behave as a traditional Component.If
HeightMode.ROW
is given, Grid will make sure that the body will display as many rows as#getHeightByRows()
defines.- Parameters:
heightMode
- the mode in to which Grid should be set
-
getHeightMode
public static HeightMode getHeightMode(com.vaadin.flow.component.grid.Grid<?> grid)
Defines the mode in which the Grid's height is calculated.If
HeightMode.CSS
is given, Grid will respect the CSS height as a traditional Component.If
HeightMode.ROW
is given, Grid will make sure that the body will display as many rows as#getHeightByRows()
defines.- Parameters:
heightMode
- the mode in to which Grid should be set- Returns:
-
responsiveStep
public static <T> GridResponsiveStep<T> responsiveStep(com.vaadin.flow.component.grid.Grid<T> grid, int minWidth)
Get or create a responsive steps for the givengrid
and minimum width.
-
getResponsiveSteps
public static <T> java.util.Collection<GridResponsiveStep<T>> getResponsiveSteps(com.vaadin.flow.component.grid.Grid<T> grid)
Return the responsive steps of the givengrid
.
-
addCheckboxColumn
public static <T> CheckboxColumn<T> addCheckboxColumn(com.vaadin.flow.component.grid.Grid<T> grid, CheckboxColumn.CheckboxColumnConfiguration<T> config)
-
toggleSelectAllCheckbox
public static <T> void toggleSelectAllCheckbox(com.vaadin.flow.component.grid.Grid<T> grid, boolean visible)
Toggles select all checkbox visibility in the grid's default header row for the selection column.Only works when Grid uses
SelectionMode.MULTI
and the data provider supplies a count callback.Note: enabling the select all checkbox when grid uses a lazy data source could lead to memory and performance issues.
- Parameters:
visible
- true to show the select all checkbox, false to hide it.- See Also:
LazySelectAllGridHelper
-
showRadioSelectionColumn
public static <T> GridRadioSelectionColumn showRadioSelectionColumn(com.vaadin.flow.component.grid.Grid<T> grid)
-
-