Class GridHelper<T>

java.lang.Object
com.flowingcode.vaadin.addons.gridhelpers.GridHelper<T>
All Implemented Interfaces:
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 Object implements Serializable
See Also:
  • Field Details

    • GRID_STYLES

      public static final String GRID_STYLES
      See Also:
    • DENSE_THEME

      @Deprecated(since="2.1.0", forRemoval=true) public static final String DENSE_THEME
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use setDenseTheme(Grid, boolean) instead. Direct use of this constant bypasses the bytecode reference to GridHelper, which prevents the Vaadin production bundle scanner from discovering the required @CssImport annotations.
      Compact row styling for Vaadin Grid.
      See Also:
  • Method Details

    • setDenseTheme

      public static void setDenseTheme(Grid<?> grid, boolean dense)
      Adds or removes compact row styling on the given grid.

      Prefer this method over grid.addThemeName(GridHelper.DENSE_THEME) because it creates a bytecode reference to GridHelper, ensuring that the Vaadin production bundle scanner discovers the required @CssImport annotations.

      Parameters:
      grid - the grid to style
      dense - true to enable dense theme, false to remove it
    • isDenseTheme

      public static boolean isDenseTheme(Grid<?> grid)
      Returns whether the dense theme is currently applied to the given grid.
      Parameters:
      grid - the grid to check
      Returns:
      true if the dense theme is applied
    • setHelperPartNameGenerator

      protected void setHelperPartNameGenerator(Class<?> clazz, SerializableFunction<T,String> generator)
    • getSelectionMode

      public static Grid.SelectionMode getSelectionMode(Grid<?> grid)
      Return the grid selection mode
    • setPartNameGenerator

      public void setPartNameGenerator(SerializableFunction<T,String> partNameGenerator)
      Sets the function that is used for generating CSS part names for all the cells in the rows in this grid. Returning null from the generator results in no custom part name being set. Multiple part names can be returned from the generator as space-separated.

      If Grid.Column.setPartNameGenerator(SerializableFunction) is used together with this method, resulting part names from both methods will be effective.

      Parameters:
      partNameGenerator - the part name generator to set.
      See Also:
    • setSelectOnClick

      public static void setSelectOnClick(Grid<?> grid, boolean selectOnClick)
    • isSelectOnClick

      public static boolean isSelectOnClick(Grid<?> grid)
    • setArrowSelectionEnabled

      public static void setArrowSelectionEnabled(Grid<?> grid, boolean value)
      Allows Grid rows to be selected using up/down arrow keys.
    • isArrowSelectionEnabled

      public static boolean isArrowSelectionEnabled(Grid<?> grid)
      Returns whether Grid rows can be selected using up/down arrow keys.
    • setSelectionColumnHidden

      public static void setSelectionColumnHidden(Grid<?> grid, boolean value)
      Sets whether the multiselect selection column is hidden.
    • setSelectionColumnFrozen

      @Deprecated public static void setSelectionColumnFrozen(Grid<?> grid, boolean value)
      Deprecated.
      Sets whether the multiselect selection column is frozen.
    • isSelectionColumnHidden

      public static boolean isSelectionColumnHidden(Grid<?> grid)
      Returns whether the multiselect selection column is hidden.
    • isSelectionColumnFrozen

      @Deprecated public static boolean isSelectionColumnFrozen(Grid<?> grid)
      Deprecated.
      Returns whether the multiselect selection column is frozen.
    • setSelectionFilter

      public static <T> void setSelectionFilter(Grid<T> grid, 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> SerializablePredicate<T> getSelectionFilter(Grid<T> grid)
      Returns the predicate for determining which rows are selectable.
    • setColumnToggleVisible

      public static void setColumnToggleVisible(Grid<?> grid, boolean visible)
      Shows a menu to toggle the visibility of grid columns.
    • isColumnToggleVisible

      public static boolean isColumnToggleVisible(Grid<?> grid)
      Returns whether the menu to toggle the visibility of grid columns is visible.
    • isHidable

      public static <T> boolean isHidable(Grid.Column<T> column)
      Returns whether this column can be hidden by the user. Default is false.
      Returns:
      true if the user can hide the column, false if not.
    • setHidable

      public static <T> Grid.Column<T> setHidable(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 configured
      hidable - true if the column may be hidden by the user via UI interaction
      Returns:
      the column.
    • addColumnToggleListener

      public static <T> Registration addColumnToggleListener(Grid<T> grid, 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(Grid.Column<T> column, 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:
      column - the column for which the hiding toggle caption is set
      caption - the text to show in the column hiding toggle
    • getHidingToggleCaption

      public static <T> String getHidingToggleCaption(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(Grid.Column<?> column)
    • setEmptyGridLabel

      public static void setEmptyGridLabel(Grid<?> grid, Component component)
      Sets a component that is displayed when the Grid would show an empty data set.
    • getEmptyGridLabel

      public static Component getEmptyGridLabel(Grid<?> grid)
      Returns the component that is displayed when the Grid would show an empty data set.
    • addToolbarFooter

      public static void addToolbarFooter(Grid<?> grid, Component toolBar)
      Adds a toolbar component to the footer of the grid.

      Note: The grid must have its columns configured before calling this method. Otherwise, an IllegalStateException will be thrown.

      Parameters:
      grid - the grid to add the toolbar to
      toolBar - the toolbar component to add
      Throws:
      IllegalStateException - if the grid columns have not been configured
    • getHeader

      @Deprecated public static String getHeader(Grid<?> grid, Grid.Column<?> column)
      Deprecated.
    • getFooter

      @Deprecated public static String getFooter(Grid<?> grid, Grid.Column<?> column)
      Deprecated.
    • setEnhancedSelectionEnabled

      public static final void setEnhancedSelectionEnabled(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(Grid<?> grid)
      Returns whether the enhanced selection is enabled.
    • setHeaderVisible

      public static void setHeaderVisible(Grid<?> grid, boolean visible)
    • isHeaderVisible

      public static boolean isHeaderVisible(Grid<?> grid)
      Returns the visibility of the header section.
      Returns:
      true if visible, false otherwise.
    • setFooterVisible

      public static void setFooterVisible(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(Grid<?> grid)
      Returns the visibility of the footer section.
      Returns:
      true if visible, false otherwise.
    • getHeaderStyles

      @Deprecated public static GridStylesHelper getHeaderStyles(Grid<?> grid, HeaderRow row)
      Returns a helper for managing CSS styles on cells within a header row.
      Parameters:
      grid - the grid containing the header row
      row - the header row to style
      Returns:
      a GridStylesHelper for managing styles on the header row's cells
    • getFooterStyles

      @Deprecated public static GridStylesHelper getFooterStyles(Grid<?> grid, FooterRow row)
      Returns a helper for managing CSS styles on cells within a footer row.
      Parameters:
      grid - the grid containing the footer row
      row - the footer row to style
      Returns:
      a GridStylesHelper for managing styles on the footer row's cells
    • getHeaderStyles

      @Deprecated public static GridStylesHelper getHeaderStyles(Grid<?> grid, HeaderRow.HeaderCell cell)
      Returns a helper for managing CSS styles on a specific header cell.
      Parameters:
      grid - the grid containing the header cell
      cell - the header cell to style
      Returns:
      a GridStylesHelper for managing styles on the header cell
    • getFooterStyles

      @Deprecated public static GridStylesHelper getFooterStyles(Grid<?> grid, FooterRow.FooterCell cell)
      Returns a helper for managing CSS styles on a specific footer cell.
      Parameters:
      grid - the grid containing the footer cell
      cell - the footer cell to style
      Returns:
      a GridStylesHelper for managing styles on the footer cell
    • setHeightByRows

      public static void setHeightByRows(Grid<?> grid, double rows)
      Sets the number of rows that should be visible in Grid's body, while getHeightMode(Grid) is HeightMode.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:
      IllegalArgumentException - if rows is zero or less
      IllegalArgumentException - if rows is infinite
      IllegalArgumentException - if rows is NaN
    • setHeightByRows

      public static void setHeightByRows(Grid<?> grid, int rows)
      Sets the number of rows that should be visible in Grid's body, while getHeightMode(Grid) is HeightMode.ROW.

      If Grid is currently not in HeightMode.ROW, the given value is remembered, and applied once the mode is applied. @See setHeightByRows(Grid, double)

    • getHeightByRows

      public static double getHeightByRows(Grid<?> grid)
      Gets the amount of rows in Grid's body that are shown, while getHeightMode(Grid) is HeightMode.ROW.
      Returns:
      the amount of rows that are being shown in Grid's body
      See Also:
    • setHeightMode

      public static void setHeightMode(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 a setHeight-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(Grid) defines.

      Parameters:
      heightMode - the mode in to which Grid should be set
    • getHeightMode

      public static HeightMode getHeightMode(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(Grid) defines.

      Returns:
      the mode in which the Grid is set
    • responsiveStep

      public static <T> GridResponsiveStep<T> responsiveStep(Grid<T> grid, int minWidth)
      Get or create a responsive steps for the given grid and minimum width.
    • getResponsiveSteps

      public static <T> Collection<GridResponsiveStep<T>> getResponsiveSteps(Grid<T> grid)
      Return the responsive steps of the given grid.
    • addCheckboxColumn

      public static <T> CheckboxColumn<T> addCheckboxColumn(Grid<T> grid, CheckboxColumn.CheckboxColumnConfiguration<T> config)
    • toggleSelectAllCheckbox

      public static <T> void toggleSelectAllCheckbox(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 Grid.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(Grid<T> grid)