Skip to content

Commit

Permalink
fix #987 Allow DataTable's SortPlugin to Trigger Less Strictly
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Dec 22, 2024
1 parent d1118d1 commit ac3aacc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -144,6 +145,7 @@ public void onHeaderAdded(DataTable<T> dataTable, ColumnConfig<T> column) {
mouseEvent.preventDefault();
this.resizingColumn = column;
this.resizing = true;
this.datatable.applyMeta(AttributeMeta.of(DUI_DT_COL_RESIZING, true));
column
.getGrandParent()
.applyAndOnSubColumns(
Expand All @@ -165,6 +167,7 @@ public void onHeaderAdded(DataTable<T> dataTable, ColumnConfig<T> column) {
evt.stopPropagation();
if (column.equals(this.resizingColumn) && resizing) {
this.resizing = false;

ResizeColumnMeta.get(column)
.ifPresent(
meta -> {
Expand All @@ -178,6 +181,11 @@ public void onHeaderAdded(DataTable<T> dataTable, ColumnConfig<T> column) {

DominoDom.document.body.removeEventListener(
EventType.mousemove.getName(), resizeListener);
DomGlobal.setTimeout(
p -> {
this.datatable.removeMeta(DUI_DT_COL_RESIZING);
},
300);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,31 +70,17 @@ public void onHeaderAdded(DataTable<T> dataTable, ColumnConfig<T> 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;
});
}
}
Expand Down

0 comments on commit ac3aacc

Please sign in to comment.