Skip to content

Commit fac5154

Browse files
javier-godoypaodb
authored andcommitted
fix: fix filterable column display
Close #123
1 parent d6a5ef4 commit fac5154

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public enum Orientation {
145145

146146
private boolean isFromClient = false;
147147

148+
private boolean explicitHeaderRow = true;
149+
148150
private static <T> ListDataProvider<T> emptyDataProvider() {
149151
return DataProvider.ofCollection(new LinkedHashSet<>());
150152
}
@@ -455,6 +457,39 @@ public TwinColGrid<T> withSelectionGridCaption(final String caption) {
455457
return this;
456458
}
457459

460+
/**
461+
* Configure this component to create the first header row (for column header labels). If no
462+
* column will have a header, this property must be set to {@code false}.
463+
*
464+
* <p>
465+
* When this property is {@code true} (default), the first column added through this component
466+
* will {@linkplain Grid#appendHeaderRow() append} a header row, which will be the "default header
467+
* row" (used by {@code Column.setHeader}). If no headers are set, then the default header row
468+
* will be empty.
469+
*
470+
* <p>
471+
* When this property is {@code false}, then {@code Column.setHeader} will allocate a header row
472+
* when called (which prevents an empty row if no headers are set, but also replaces the filter
473+
* componentes).
474+
*
475+
* @param value whether the first header row will be created when a column is added.
476+
* @return this instance
477+
*/
478+
public TwinColGrid<T> createFirstHeaderRow(boolean value) {
479+
explicitHeaderRow = value;
480+
return this;
481+
}
482+
483+
private void createFirstHeaderRowIfNeeded() {
484+
if (explicitHeaderRow) {
485+
forEachGrid(grid -> {
486+
if (grid.getColumns().isEmpty() && grid.getHeaderRows().isEmpty()) {
487+
grid.appendHeaderRow();
488+
}
489+
});
490+
}
491+
}
492+
458493
/**
459494
* Adds a column to each grids. Both columns will use a {@link TextRenderer} and the value
460495
* will be converted to a String by using the provided {@code itemLabelGenerator}.
@@ -463,6 +498,7 @@ public TwinColGrid<T> withSelectionGridCaption(final String caption) {
463498
* @return the pair of columns
464499
*/
465500
public TwinColumn<T> addColumn(ItemLabelGenerator<T> itemLabelGenerator) {
501+
createFirstHeaderRowIfNeeded();
466502
Column<T> availableColumn =
467503
getAvailableGrid().addColumn(new TextRenderer<>(itemLabelGenerator));
468504
Column<T> selectionColumn =
@@ -800,6 +836,8 @@ public FilterableTwinColumn<T> addFilterableColumn(ItemLabelGenerator<T> itemLab
800836
public FilterableTwinColumn<T> addFilterableColumn(ItemLabelGenerator<T> itemLabelGenerator,
801837
SerializableFunction<T, String> filterableValue) {
802838

839+
createFirstHeaderRowIfNeeded();
840+
803841
Column<T> availableColumn = createFilterableColumn(available, itemLabelGenerator, filterableValue);
804842
Column<T> selectionColumn = createFilterableColumn(selection, itemLabelGenerator, filterableValue);
805843

0 commit comments

Comments
 (0)