Skip to content

Commit

Permalink
fix movable columns and range selection (#4431)
Browse files Browse the repository at this point in the history
* fix movable columns and range selection

* refactor column events naming
  • Loading branch information
azmy60 committed Apr 28, 2024
1 parent 5d16d4e commit f7708fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/js/modules/MoveColumns/MoveColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export default class MoveColumns extends Module{
headerElement = this.table.columnManager.getContentsElement(),
headersElement = this.table.columnManager.getHeadersElement();

//Prevent moving columns when range selection is active
if(this.table.modules.selectRange && this.table.modules.selectRange.columnSelection){
if(this.table.modules.selectRange.mousedown && this.table.modules.selectRange.selecting === "column"){
return;
}
}

this.moving = column;
this.startX = (this.touchMove ? e.touches[0].pageX : e.pageX) - Helpers.elOffset(element).left;

Expand Down Expand Up @@ -203,6 +210,8 @@ export default class MoveColumns extends Module{
}

this.moveHover(e);

this.dispatch("column-moving", e, this.moving);
}

_bindMouseMove(){
Expand Down Expand Up @@ -259,7 +268,7 @@ export default class MoveColumns extends Module{
if(this.toCol){
this.table.columnManager.moveColumnActual(this.moving, this.toCol, this.toColAfter);
}

this.moving = false;
this.toCol = false;
this.toColAfter = false;
Expand Down
18 changes: 18 additions & 0 deletions src/js/modules/SelectRange/SelectRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export default class SelectRange extends Module {
this.subscribe("column-mousedown", this.handleColumnMouseDown.bind(this));
this.subscribe("column-mousemove", this.handleColumnMouseMove.bind(this));
this.subscribe("column-resized", this.handleColumnResized.bind(this));
this.subscribe("column-moving", this.handleColumnMoving.bind(this));
this.subscribe("column-moved", this.handleColumnMoved.bind(this));
this.subscribe("column-width", this.layoutChange.bind(this));
this.subscribe("column-height", this.layoutChange.bind(this));
this.subscribe("column-resized", this.layoutChange.bind(this));
Expand Down Expand Up @@ -304,10 +306,26 @@ export default class SelectRange extends Module {
});
}

handleColumnMoving(_event, column) {
this.resetRanges().setBounds(column);
this.overlay.style.visibility = "hidden";
}

handleColumnMoved(from, _to, _after) {
this.activeRange.setBounds(from);
this.layoutElement();
}

handleColumnMouseDown(event, column) {
if (event.button === 2 && (this.selecting === "column" || this.selecting === "all") && this.activeRange.occupiesColumn(column)) {
return;
}

//If columns are movable, allow dragging columns only if they are not
//selected. Dragging selected columns should move the columns instead.
if(this.table.options.movableColumns && this.selecting === "column" && this.activeRange.occupiesColumn(column)){
return;
}

this.mousedown = true;

Expand Down

0 comments on commit f7708fe

Please sign in to comment.