Skip to content

Commit

Permalink
fix(table): column resize does not work with sortable columns (primef…
Browse files Browse the repository at this point in the history
…aces#16735)

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

* format fix

* fix

(cherry picked from commit cc1fe7f)
  • Loading branch information
LoaderB0T authored and Janik Schumacher committed Jan 21, 2025
1 parent 92f54b9 commit 268d9dd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/primeng/src/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ export class Table extends BaseComponent implements OnInit, AfterViewInit, After

overlaySubscription: Subscription | undefined;

resizeColumnElement: any;
resizeColumnElement: HTMLElement;

columnResizing: boolean = false;

Expand Down Expand Up @@ -2631,7 +2631,7 @@ export class Table extends BaseComponent implements OnInit, AfterViewInit, After

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 @@ -2656,22 +2656,23 @@ export class Table extends BaseComponent implements OnInit, AfterViewInit, After
}

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

0 comments on commit 268d9dd

Please sign in to comment.