@@ -145,6 +145,8 @@ public enum Orientation {
145
145
146
146
private boolean isFromClient = false ;
147
147
148
+ private boolean explicitHeaderRow = true ;
149
+
148
150
private static <T > ListDataProvider <T > emptyDataProvider () {
149
151
return DataProvider .ofCollection (new LinkedHashSet <>());
150
152
}
@@ -455,6 +457,39 @@ public TwinColGrid<T> withSelectionGridCaption(final String caption) {
455
457
return this ;
456
458
}
457
459
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
+
458
493
/**
459
494
* Adds a column to each grids. Both columns will use a {@link TextRenderer} and the value
460
495
* will be converted to a String by using the provided {@code itemLabelGenerator}.
@@ -463,6 +498,7 @@ public TwinColGrid<T> withSelectionGridCaption(final String caption) {
463
498
* @return the pair of columns
464
499
*/
465
500
public TwinColumn <T > addColumn (ItemLabelGenerator <T > itemLabelGenerator ) {
501
+ createFirstHeaderRowIfNeeded ();
466
502
Column <T > availableColumn =
467
503
getAvailableGrid ().addColumn (new TextRenderer <>(itemLabelGenerator ));
468
504
Column <T > selectionColumn =
@@ -800,6 +836,8 @@ public FilterableTwinColumn<T> addFilterableColumn(ItemLabelGenerator<T> itemLab
800
836
public FilterableTwinColumn <T > addFilterableColumn (ItemLabelGenerator <T > itemLabelGenerator ,
801
837
SerializableFunction <T , String > filterableValue ) {
802
838
839
+ createFirstHeaderRowIfNeeded ();
840
+
803
841
Column <T > availableColumn = createFilterableColumn (available , itemLabelGenerator , filterableValue );
804
842
Column <T > selectionColumn = createFilterableColumn (selection , itemLabelGenerator , filterableValue );
805
843
0 commit comments