Skip to content

Commit 7f2523c

Browse files
committed
fix #144 Data table with fixed height, but flexible (auto) column width
1 parent acf3b1a commit 7f2523c

File tree

6 files changed

+96
-11
lines changed

6 files changed

+96
-11
lines changed

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/ColumnConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,9 @@ private ColumnHeader createColumnElement(TableConfig<T> tableConfig) {
11071107

11081108
applyScreenMedia(this.headElement.element());
11091109

1110-
if (tableConfig.isFixed() || isFixed()) {
1110+
if (tableConfig.getTableMode() == TableMode.FIXED_HEIGHT
1111+
|| tableConfig.getTableMode() == TableMode.AUTO
1112+
|| isFixed()) {
11111113
fixElementWidth(this, this.headElement.element());
11121114
}
11131115

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/DataTable.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,23 @@ private DataTable<T> init() {
232232
this.dataStore.load();
233233
}
234234

235-
if (tableConfig.isFixed()) {
236-
tableElement.setMaxHeight(tableConfig.getFixedBodyHeight());
235+
if (tableConfig.getTableMode() == TableMode.AUTO
236+
|| tableConfig.getTableMode() == TableMode.FIXED_HEIGHT) {
237+
if (nonNull(tableConfig.getFixedBodyHeight())
238+
&& !tableConfig.getFixedBodyHeight().isEmpty()) {
239+
this.setCssProperty("--dui-datatable-fixed-body-height", tableConfig.getFixedBodyHeight());
240+
}
237241
}
238242

239-
if (tableConfig.isFixed()) {
243+
if (tableConfig.getTableMode() == TableMode.FIXED_HEIGHT) {
240244
dui_datatable_width_full.remove(this);
241245
this.addCss(dui_datatable_fixed);
242246
ColumnUtils.fixElementWidth(this, tableElement.element());
243-
}
244-
245-
if (tableConfig.isFixed()) {
247+
} else if (tableConfig.getTableMode() == TableMode.AUTO) {
248+
this.addCss(dui_datatable_auto);
246249
ColumnUtils.fixElementWidth(this, tableElement.element());
247250
}
251+
248252
return this;
249253
}
250254

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/DataTableStyles.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public interface DataTableStyles {
3535
CssClass dui_datatable_width_full = () -> "dui-datatable-width-full";
3636

3737
CssClass dui_datatable_fixed = () -> "dui-datatable-fixed";
38+
CssClass dui_datatable_auto = () -> "dui-datatable-auto";
3839

3940
CssClass dui_datatable_row = () -> "dui-datatable-row";
4041

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public class TableConfig<T>
5858
private List<ColumnConfig<T>> columns = new LinkedList<>();
5959
private List<DataTablePlugin<T>> plugins = new ArrayList<>();
6060
private DataTable<T> dataTable;
61-
private boolean fixed = false;
61+
private TableMode tableMode = TableMode.DEFAULT;
6262
private String fixedDefaultColumnWidth = "100px";
63-
private String fixedBodyHeight = "400px";
63+
private String fixedBodyHeight = "";
6464
private boolean lazyLoad = true;
6565
private boolean multiSelect = true;
6666
private boolean stickyHeader = false;
@@ -275,22 +275,50 @@ public interface UtilityColumnHandler<T> {
275275
* Checks if the DataTable is in a fixed layout mode.
276276
*
277277
* @return {@code true} if the table layout is fixed, {@code false} otherwise.
278+
* @deprecated use {@link #getTableMode()} instead
278279
*/
280+
@Deprecated
279281
public boolean isFixed() {
280-
return fixed;
282+
return TableMode.FIXED_HEIGHT.equals(tableMode);
281283
}
282284

283285
/**
284286
* Sets the DataTable layout mode as fixed or fluid.
285287
*
286288
* @param fixed {@code true} to set the table layout as fixed, {@code false} for fluid.
287289
* @return The current instance of {@link TableConfig} for chaining.
290+
* @deprecated use {@link #setTableMode(TableMode)} instead
288291
*/
292+
@Deprecated
289293
public TableConfig<T> setFixed(boolean fixed) {
290-
this.fixed = fixed;
294+
this.tableMode = TableMode.FIXED_HEIGHT;
291295
return this;
292296
}
293297

298+
/**
299+
* Sets the table mode for the table configuration.
300+
*
301+
* @param tableMode the mode to set for the table, defining its operational behavior or format
302+
* @return the updated TableConfig instance with the newly set table mode
303+
*/
304+
public TableConfig<T> setTableMode(TableMode tableMode) {
305+
if (nonNull(tableMode)) {
306+
this.tableMode = tableMode;
307+
} else {
308+
this.tableMode = TableMode.DEFAULT;
309+
}
310+
return this;
311+
}
312+
313+
/**
314+
* Retrieves the current mode of the table.
315+
*
316+
* @return the current TableMode instance representing the table's mode.
317+
*/
318+
public TableMode getTableMode() {
319+
return tableMode;
320+
}
321+
294322
/**
295323
* Checks if the DataTable is in lazy load mode.
296324
*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.datatable;
17+
18+
/**
19+
* Represents different display modes for an HTML table layout.
20+
*
21+
* <p>This enum provides three configurations for rendering table structures. Each mode offers a
22+
* distinct combination of layout settings, column behavior, and table header interactions. These
23+
* modes determine how the table is displayed and how it adjusts to content and container size.
24+
*/
25+
public enum TableMode {
26+
27+
/**
28+
* Default HTML table layout: columns are sized by content and available table width, height grows
29+
* with content, column widths are not fixed, and headers are not sticky.
30+
*/
31+
DEFAULT,
32+
/** Block table display, with fixed table body height and fixed columns width. */
33+
FIXED_HEIGHT,
34+
/** Fixed table layout with fixed and auto columns widths,sticky headers. */
35+
AUTO;
36+
}

domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-datatable.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
display: block;
1717
overflow-x: auto;
1818
max-width: 100%;
19+
max-height: var(--dui-datatable-fixed-body-height, 400px);
20+
}
21+
22+
.dui-datatable-responsive.dui-datatable-auto {
23+
max-height: var(--dui-datatable-fixed-body-height, 400px);
24+
overflow-y: auto;
25+
}
26+
27+
.dui-datatable-responsive.dui-datatable-auto .dui-datatable {
28+
display: table;
29+
table-layout: fixed;
30+
max-width: 100%;
31+
width: 100%;
1932
}
2033

2134
.dui-datatable-thead {
@@ -36,6 +49,7 @@
3649
border-top: 1px solid var(--dui-accent-l-4);
3750
}
3851

52+
.dui-datatable-auto .dui-datatable-thead,
3953
.dui-datatable-fixed .dui-datatable-thead {
4054
position: sticky;
4155
top: 0;

0 commit comments

Comments
 (0)