Skip to content

Commit acf3b1a

Browse files
committed
fix #1107 DataTable-GroupingPlugin: Entire group row should be clickable
1 parent e141610 commit acf3b1a

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/grouping/GroupingPlugin.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.dominokit.domino.ui.datatable.TableRow;
2929
import org.dominokit.domino.ui.datatable.events.OnBeforeDataChangeEvent;
3030
import org.dominokit.domino.ui.datatable.plugins.DataTablePlugin;
31+
import org.dominokit.domino.ui.datatable.plugins.HasPluginConfig;
3132
import org.dominokit.domino.ui.elements.DivElement;
3233
import org.dominokit.domino.ui.icons.ToggleIcon;
3334
import org.dominokit.domino.ui.icons.ToggleMdiIcon;
@@ -63,13 +64,17 @@
6364
*
6465
* @param <T> The data type of the DataTable.
6566
*/
66-
public class GroupingPlugin<T> implements DataTablePlugin<T>, TableConfig.RowAppender<T> {
67+
public class GroupingPlugin<T>
68+
implements DataTablePlugin<T>,
69+
TableConfig.RowAppender<T>,
70+
HasPluginConfig<T, GroupingPlugin<T>, GroupingPluginConfig> {
6771

6872
private Map<String, DataGroup<T>> dataGroups = new HashMap<>();
6973
private final GroupSupplier<T> groupSupplier;
7074
private GroupCellRenderer<T> groupRenderer;
7175
private Supplier<ToggleIcon<?, ?>> groupExpandedCollapseIconSupplier =
7276
() -> ToggleMdiIcon.create(Icons.minus_box(), Icons.plus_box());
77+
private GroupingPluginConfig config = new GroupingPluginConfig();
7378

7479
/**
7580
* Creates a new {@code GroupingPlugin} instance with the given group supplier and group renderer.
@@ -131,15 +136,27 @@ public void appendRow(DataTable<T> dataTable, TableRow<T> tableRow) {
131136
GroupCell<T> groupCell = new GroupCell<>(cellInfo);
132137
DataGroup<T> dataGroup = new DataGroup<>(tableRow, groupCell);
133138

134-
ToggleIcon<?, ?> groupIconSupplier =
139+
ToggleIcon<?, ?> groupToggleIcon =
135140
groupExpandedCollapseIconSupplier
136141
.get()
137142
.clickable()
138143
.toggleOnClick(true)
139-
.addClickListener(evt -> dataGroup.toggleGroup());
140-
dataGroup.setGroupIconSupplier(groupIconSupplier).setGroupRenderer(groupRenderer).render();
144+
.addClickListener(
145+
evt -> {
146+
evt.stopPropagation();
147+
dataGroup.toggleGroup();
148+
});
149+
dataGroup.setGroupIconSupplier(groupToggleIcon).setGroupRenderer(groupRenderer).render();
150+
151+
if (config.isToggleGroupOnClick()) {
152+
groupCell.addClickListener(
153+
evt -> {
154+
dataGroup.toggleGroup();
155+
groupToggleIcon.toggle();
156+
});
157+
}
141158

142-
groupPrefix.appendChild(groupIconSupplier);
159+
groupPrefix.appendChild(groupToggleIcon);
143160

144161
dataTable
145162
.bodyElement()
@@ -201,6 +218,21 @@ public void handleEvent(DominoEvent event) {
201218
}
202219
}
203220

221+
@Override
222+
public GroupingPlugin<T> setConfig(GroupingPluginConfig config) {
223+
if (nonNull(config)) {
224+
this.config = config;
225+
} else {
226+
this.config = GroupingPluginConfig.create();
227+
}
228+
return this;
229+
}
230+
231+
@Override
232+
public GroupingPluginConfig getConfig() {
233+
return this.config;
234+
}
235+
204236
/**
205237
* The {@code DataGroup} class represents a group of data rows in the DataTable. It is used for
206238
* grouping and rendering data rows as a single group.
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.plugins.grouping;
17+
18+
import org.dominokit.domino.ui.datatable.plugins.PluginConfig;
19+
20+
public class GroupingPluginConfig implements PluginConfig {
21+
22+
private boolean toggleGroupOnClick;
23+
24+
public static GroupingPluginConfig create() {
25+
return new GroupingPluginConfig();
26+
}
27+
28+
public boolean isToggleGroupOnClick() {
29+
return toggleGroupOnClick;
30+
}
31+
32+
public GroupingPluginConfig setToggleGroupOnClick(boolean toggleGroupOnClick) {
33+
this.toggleGroupOnClick = toggleGroupOnClick;
34+
return this;
35+
}
36+
}

0 commit comments

Comments
 (0)