|
28 | 28 | import org.dominokit.domino.ui.datatable.TableRow; |
29 | 29 | import org.dominokit.domino.ui.datatable.events.OnBeforeDataChangeEvent; |
30 | 30 | import org.dominokit.domino.ui.datatable.plugins.DataTablePlugin; |
| 31 | +import org.dominokit.domino.ui.datatable.plugins.HasPluginConfig; |
31 | 32 | import org.dominokit.domino.ui.elements.DivElement; |
32 | 33 | import org.dominokit.domino.ui.icons.ToggleIcon; |
33 | 34 | import org.dominokit.domino.ui.icons.ToggleMdiIcon; |
|
63 | 64 | * |
64 | 65 | * @param <T> The data type of the DataTable. |
65 | 66 | */ |
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> { |
67 | 71 |
|
68 | 72 | private Map<String, DataGroup<T>> dataGroups = new HashMap<>(); |
69 | 73 | private final GroupSupplier<T> groupSupplier; |
70 | 74 | private GroupCellRenderer<T> groupRenderer; |
71 | 75 | private Supplier<ToggleIcon<?, ?>> groupExpandedCollapseIconSupplier = |
72 | 76 | () -> ToggleMdiIcon.create(Icons.minus_box(), Icons.plus_box()); |
| 77 | + private GroupingPluginConfig config = new GroupingPluginConfig(); |
73 | 78 |
|
74 | 79 | /** |
75 | 80 | * 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) { |
131 | 136 | GroupCell<T> groupCell = new GroupCell<>(cellInfo); |
132 | 137 | DataGroup<T> dataGroup = new DataGroup<>(tableRow, groupCell); |
133 | 138 |
|
134 | | - ToggleIcon<?, ?> groupIconSupplier = |
| 139 | + ToggleIcon<?, ?> groupToggleIcon = |
135 | 140 | groupExpandedCollapseIconSupplier |
136 | 141 | .get() |
137 | 142 | .clickable() |
138 | 143 | .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 | + } |
141 | 158 |
|
142 | | - groupPrefix.appendChild(groupIconSupplier); |
| 159 | + groupPrefix.appendChild(groupToggleIcon); |
143 | 160 |
|
144 | 161 | dataTable |
145 | 162 | .bodyElement() |
@@ -201,6 +218,21 @@ public void handleEvent(DominoEvent event) { |
201 | 218 | } |
202 | 219 | } |
203 | 220 |
|
| 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 | + |
204 | 236 | /** |
205 | 237 | * The {@code DataGroup} class represents a group of data rows in the DataTable. It is used for |
206 | 238 | * grouping and rendering data rows as a single group. |
|
0 commit comments