Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/primefaces/primeng
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Oct 14, 2023
2 parents 386092d + a99b0c1 commit 733b9cc
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2519,28 +2519,6 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
return widths;
}

resizeTableCells(newColumnWidth: number, nextColumnWidth: number | null) {
let colIndex = DomHandler.index(this.resizeColumnElement);
let width = this.columnResizeMode === 'expand' ? this._initialColWidths : this._totalTableWidth();

this.destroyStyleElement();
this.createStyleElement();

let innerHTML = '';
width.forEach((width, index) => {
let colWidth = index === colIndex ? newColumnWidth : nextColumnWidth && index === colIndex + 1 ? nextColumnWidth : width;
let style = `width: ${colWidth}px !important; max-width: ${colWidth}px !important;`;
innerHTML += `
#${this.id}-table > .p-datatable-thead > tr > th:nth-child(${index + 1}),
#${this.id}-table > .p-datatable-tbody > tr > td:nth-child(${index + 1}),
#${this.id}-table > .p-datatable-tfoot > tr > td:nth-child(${index + 1}) {
${style}
}
`;
});
this.renderer.setProperty(this.styleElement, 'innerHTML', innerHTML);
}

onColumnDragStart(event: any, columnElement: any) {
this.reorderIconWidth = DomHandler.getHiddenElementOuterWidth(this.reorderIndicatorUpViewChild?.nativeElement);
this.reorderIconHeight = DomHandler.getHiddenElementOuterHeight(this.reorderIndicatorDownViewChild?.nativeElement);
Expand Down Expand Up @@ -2623,6 +2601,12 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
}
}

if (this.resizableColumns && this.resizeColumnElement && this.resizeColumnElement.isSameNode(this.draggedColumn)) {
let width = this.columnResizeMode === 'expand' ? this._initialColWidths : this._totalTableWidth();
ObjectUtils.reorderArray(width, dragIndex + 1, dropIndex + 1);
this.updateStyleElement(width, dragIndex, null, null);
}

(<ElementRef>this.reorderIndicatorUpViewChild).nativeElement.style.display = 'none';
(<ElementRef>this.reorderIndicatorDownViewChild).nativeElement.style.display = 'none';
this.draggedColumn.draggable = false;
Expand All @@ -2631,6 +2615,31 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
}
}

resizeTableCells(newColumnWidth: number, nextColumnWidth: number | null) {
let colIndex = DomHandler.index(this.resizeColumnElement);
let width = this.columnResizeMode === 'expand' ? this._initialColWidths : this._totalTableWidth();
this.updateStyleElement(width, colIndex, newColumnWidth, nextColumnWidth);
}

updateStyleElement(width: number[], colIndex: number, newColumnWidth: number, nextColumnWidth: number | null) {
this.destroyStyleElement();
this.createStyleElement();

let innerHTML = '';
width.forEach((width, index) => {
let colWidth = index === colIndex ? newColumnWidth : nextColumnWidth && index === colIndex + 1 ? nextColumnWidth : width;
let style = `width: ${colWidth}px !important; max-width: ${colWidth}px !important;`;
innerHTML += `
#${this.id}-table > .p-datatable-thead > tr > th:nth-child(${index + 1}),
#${this.id}-table > .p-datatable-tbody > tr > td:nth-child(${index + 1}),
#${this.id}-table > .p-datatable-tfoot > tr > td:nth-child(${index + 1}) {
${style}
}
`;
});
this.renderer.setProperty(this.styleElement, 'innerHTML', innerHTML);
}

onRowDragStart(event: any, index: number) {
this.rowDragging = true;
this.draggedRowIndex = index;
Expand Down

1 comment on commit 733b9cc

@vercel
Copy link

@vercel vercel bot commented on 733b9cc Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.