Skip to content
Merged
Show file tree
Hide file tree
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[sorts]="sorts()"
[sortType]="sortType()"
[scrollbarH]="scrollbarH()"
[innerWidth]="_innerWidth"
[innerWidth]="_innerWidth()"
[offsetX]="_offsetX"
[dealsWithGroup]="_internalGroupedRows() !== undefined"
[columns]="_internalColumns()"
Expand Down Expand Up @@ -50,8 +50,8 @@
[offsetX]="_offsetX"
[rowDetail]="rowDetail"
[groupHeader]="groupHeader"
[innerWidth]="_innerWidth"
[bodyHeight]="bodyHeight"
[innerWidth]="_innerWidth()"
[bodyHeight]="bodyHeight()"
[selectionType]="selectionType()"
[rowIdentity]="rowIdentity"
[rowClass]="rowClass()"
Expand Down
31 changes: 15 additions & 16 deletions projects/ngx-datatable/src/lib/components/datatable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,18 @@ export class DatatableComponent<TRow extends Row = any>
}

element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
_innerWidth!: number;
readonly _innerWidth = computed(() => this.dimensions().width);
pageSize!: number;
bodyHeight!: number;
readonly bodyHeight = computed(() => {
if (this.scrollbarV()) {
let height = this.dimensions().height;
if (this.headerElement) {
height = height - this.headerElement.nativeElement.getBoundingClientRect().height;
}
return height - this.footerHeight();
}
return 0;
});
rowCount = 0;
rowDiffer: IterableDiffer<TRow | undefined> = inject(IterableDiffers).find([]).create();
/** This counter is increased, when the rowDiffer detects a change. This will cause an update of _internalRows. */
Expand Down Expand Up @@ -745,6 +754,7 @@ export class DatatableComponent<TRow extends Row = any>
// this makes horizontal scroll to appear on load even if columns can fit in view
// this will be set to true once rows are available and rendered on UI
private readonly _rowInitDone = signal(false);
private readonly dimensions = signal<Pick<DOMRect, 'width' | 'height'>>({ height: 0, width: 0 });

constructor() {
// TODO: This should be a computed signal.
Expand Down Expand Up @@ -906,7 +916,7 @@ export class DatatableComponent<TRow extends Row = any>
forceIdx = -1,
allowBleed: boolean = this.scrollbarH()
): TableColumnInternal[] {
let width = this._innerWidth;
let width = this._innerWidth();
if (!width) {
return [];
}
Expand Down Expand Up @@ -941,18 +951,7 @@ export class DatatableComponent<TRow extends Row = any>
*/
recalculateDims(): void {
const dims = this.element.getBoundingClientRect();
this._innerWidth = Math.floor(dims.width);

if (this.scrollbarV()) {
let height = dims.height;
if (this.headerElement) {
height = height - this.headerElement.nativeElement.getBoundingClientRect().height;
}
if (this.footerHeight()) {
height = height - this.footerHeight();
}
this.bodyHeight = height;
}
this.dimensions.set(dims);

this.recalculatePages();
}
Expand Down Expand Up @@ -1028,7 +1027,7 @@ export class DatatableComponent<TRow extends Row = any>
// This is because an expanded row is still considered to be a child of
// the original row. Hence calculation would use rowHeight only.
if (this.scrollbarV() && this.virtualization()) {
const size = Math.ceil(this.bodyHeight / (this.rowHeight() as number));
const size = Math.ceil(this.bodyHeight() / (this.rowHeight() as number));
return Math.max(size, 0);
}

Expand Down
Loading