Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): column resize does not work with sortable columns #16735

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable

overlaySubscription: Subscription | undefined;

resizeColumnElement: any;
resizeColumnElement: HTMLElement;

columnResizing: boolean = false;

Expand Down Expand Up @@ -2511,7 +2511,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable

onColumnResizeBegin(event: any) {
let containerLeft = DomHandler.getOffset(this.containerViewChild?.nativeElement).left;
this.resizeColumnElement = event.target.parentElement;
this.resizeColumnElement = event.target.closest('th');
this.columnResizing = true;
if (event.type == 'touchstart') {
this.lastResizerHelperX = event.changedTouches[0].clientX - containerLeft + this.containerViewChild?.nativeElement.scrollLeft;
Expand All @@ -2536,22 +2536,23 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
}

onColumnResizeEnd() {
let delta = this.resizeHelperViewChild?.nativeElement.offsetLeft - <number>this.lastResizerHelperX;
let columnWidth = this.resizeColumnElement.offsetWidth;
let newColumnWidth = columnWidth + delta;
let minWidth = this.resizeColumnElement.style.minWidth.replace(/[^\d.]/g, '') || 15;
const delta = this.resizeHelperViewChild?.nativeElement.offsetLeft - <number>this.lastResizerHelperX;
const columnWidth = this.resizeColumnElement.offsetWidth;
const newColumnWidth = columnWidth + delta;
const elementMinWidth = this.resizeColumnElement.style.minWidth.replace(/[^\d.]/g, '');
const minWidth = elementMinWidth ? parseFloat(elementMinWidth) : 15;

if (newColumnWidth >= minWidth) {
if (this.columnResizeMode === 'fit') {
let nextColumn = this.resizeColumnElement.nextElementSibling;
let nextColumnWidth = nextColumn.offsetWidth - delta;
const nextColumn = this.resizeColumnElement.nextElementSibling as HTMLElement;
const nextColumnWidth = nextColumn.offsetWidth - delta;

if (newColumnWidth > 15 && nextColumnWidth > 15) {
this.resizeTableCells(newColumnWidth, nextColumnWidth);
}
} else if (this.columnResizeMode === 'expand') {
this._initialColWidths = this._totalTableWidth();
let tableWidth = this.tableViewChild?.nativeElement.offsetWidth + delta;
const tableWidth = this.tableViewChild?.nativeElement.offsetWidth + delta;

this.setResizeTableWidth(tableWidth + 'px');
this.resizeTableCells(newColumnWidth, null);
Expand Down
Loading