diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java index 2a511b1..dcf65ca 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java @@ -145,6 +145,8 @@ public enum Orientation { private boolean isFromClient = false; + private boolean explicitHeaderRow = true; + private static ListDataProvider emptyDataProvider() { return DataProvider.ofCollection(new LinkedHashSet<>()); } @@ -455,6 +457,39 @@ public TwinColGrid withSelectionGridCaption(final String caption) { return this; } + /** + * Configure this component to create the first header row (for column header labels). If no + * column will have a header, this property must be set to {@code false}. + * + *

+ * When this property is {@code true} (default), the first column added through this component + * will {@linkplain Grid#appendHeaderRow() append} a header row, which will be the "default header + * row" (used by {@code Column.setHeader}). If no headers are set, then the default header row + * will be empty. + * + *

+ * When this property is {@code false}, then {@code Column.setHeader} will allocate a header row + * when called (which prevents an empty row if no headers are set, but also replaces the filter + * componentes). + * + * @param value whether the first header row will be created when a column is added. + * @return this instance + */ + public TwinColGrid createFirstHeaderRow(boolean value) { + explicitHeaderRow = value; + return this; + } + + private void createFirstHeaderRowIfNeeded() { + if (explicitHeaderRow) { + forEachGrid(grid -> { + if (grid.getColumns().isEmpty() && grid.getHeaderRows().isEmpty()) { + grid.appendHeaderRow(); + } + }); + } + } + /** * Adds a column to each grids. Both columns will use a {@link TextRenderer} and the value * will be converted to a String by using the provided {@code itemLabelGenerator}. @@ -463,6 +498,7 @@ public TwinColGrid withSelectionGridCaption(final String caption) { * @return the pair of columns */ public TwinColumn addColumn(ItemLabelGenerator itemLabelGenerator) { + createFirstHeaderRowIfNeeded(); Column availableColumn = getAvailableGrid().addColumn(new TextRenderer<>(itemLabelGenerator)); Column selectionColumn = @@ -800,6 +836,8 @@ public FilterableTwinColumn addFilterableColumn(ItemLabelGenerator itemLab public FilterableTwinColumn addFilterableColumn(ItemLabelGenerator itemLabelGenerator, SerializableFunction filterableValue) { + createFirstHeaderRowIfNeeded(); + Column availableColumn = createFilterableColumn(available, itemLabelGenerator, filterableValue); Column selectionColumn = createFilterableColumn(selection, itemLabelGenerator, filterableValue);