From ac3aaccb36a020dde103d225c6d70492ffbacd92 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Sun, 22 Dec 2024 11:00:20 +0300 Subject: [PATCH] fix #987 Allow DataTable's SortPlugin to Trigger Less Strictly --- .../datatable/plugins/PluginsConstants.java | 20 +++++++++++++++++++ .../plugins/column/ResizeColumnsPlugin.java | 10 +++++++++- .../plugins/pagination/SortPlugin.java | 17 ++-------------- 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/PluginsConstants.java diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/PluginsConstants.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/PluginsConstants.java new file mode 100644 index 000000000..fb3b913bf --- /dev/null +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/PluginsConstants.java @@ -0,0 +1,20 @@ +/* + * Copyright © 2019 Dominokit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.dominokit.domino.ui.datatable.plugins; + +public final class PluginsConstants { + public static final String DUI_DT_COL_RESIZING = "dui-dt-resizing"; +} diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/column/ResizeColumnsPlugin.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/column/ResizeColumnsPlugin.java index c8f57b79d..55e8ca3e4 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/column/ResizeColumnsPlugin.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/column/ResizeColumnsPlugin.java @@ -17,7 +17,7 @@ package org.dominokit.domino.ui.datatable.plugins.column; import static org.dominokit.domino.ui.datatable.DataTableStyles.dui_column_resizer; -import static org.dominokit.domino.ui.utils.Domino.*; +import static org.dominokit.domino.ui.datatable.plugins.PluginsConstants.DUI_DT_COL_RESIZING; import static org.dominokit.domino.ui.utils.Unit.px; import elemental2.dom.DomGlobal; @@ -33,6 +33,7 @@ import org.dominokit.domino.ui.events.EventType; import org.dominokit.domino.ui.utils.DominoCSSRule; import org.dominokit.domino.ui.utils.DominoDom; +import org.dominokit.domino.ui.utils.meta.AttributeMeta; /** * A DataTable plugin that allows users to resize column widths via drag-and-drop. @@ -144,6 +145,7 @@ public void onHeaderAdded(DataTable dataTable, ColumnConfig column) { mouseEvent.preventDefault(); this.resizingColumn = column; this.resizing = true; + this.datatable.applyMeta(AttributeMeta.of(DUI_DT_COL_RESIZING, true)); column .getGrandParent() .applyAndOnSubColumns( @@ -165,6 +167,7 @@ public void onHeaderAdded(DataTable dataTable, ColumnConfig column) { evt.stopPropagation(); if (column.equals(this.resizingColumn) && resizing) { this.resizing = false; + ResizeColumnMeta.get(column) .ifPresent( meta -> { @@ -178,6 +181,11 @@ public void onHeaderAdded(DataTable dataTable, ColumnConfig column) { DominoDom.document.body.removeEventListener( EventType.mousemove.getName(), resizeListener); + DomGlobal.setTimeout( + p -> { + this.datatable.removeMeta(DUI_DT_COL_RESIZING); + }, + 300); } }; diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/SortPlugin.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/SortPlugin.java index 753d0a226..37a43c249 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/SortPlugin.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/SortPlugin.java @@ -17,6 +17,7 @@ package org.dominokit.domino.ui.datatable.plugins.pagination; import static java.util.Objects.nonNull; +import static org.dominokit.domino.ui.datatable.plugins.PluginsConstants.DUI_DT_COL_RESIZING; import static org.dominokit.domino.ui.utils.Domino.*; import elemental2.dom.HTMLElement; @@ -69,31 +70,17 @@ public void onHeaderAdded(DataTable dataTable, ColumnConfig column) { if (column.isSortable()) { SortContext sortContext = new SortContext(column.getSortKey(), config); sortContainers.put(column.getSortKey(), sortContext); - final boolean[] moving = new boolean[] {false}; column.appendChild(div().addCss(dui_order_100).appendChild(sortContext.sortElement)); column.getHeadElement().addCss(dui_cursor_pointer, dui_disable_text_select); - column - .getHeadElement() - .addEventListener( - EventType.mousemove.getName(), - evt -> { - moving[0] = true; - }) - .addEventListener( - EventType.mousedown.getName(), - evt -> { - moving[0] = false; - }); column .getHeadElement() .addEventListener( EventType.click.getName(), evt -> { - if (!moving[0]) { + if (this.dataTable.getMeta(DUI_DT_COL_RESIZING).isEmpty()) { updateSort(sortContext); fireSortEvent(currentSortContext.sortDirection, column); } - moving[0] = false; }); } }