@progress/kendo-angular-grid
Version:
Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.
56 lines (55 loc) • 1.77 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
/**
* @hidden
*/
export class RowHeightService {
total;
offsets = [];
heights = [];
constructor(total = 0, rowHeight) {
this.total = total;
let agg = 0;
for (let idx = 0; idx < total; idx++) {
this.offsets.push(agg);
agg += rowHeight;
this.heights.push(rowHeight);
}
}
height(rowIndex) {
return this.heights[rowIndex];
}
index(position) {
for (let i = 0; i < this.offsets.length; i++) {
if (position === this.offsets[i]) {
return i;
}
if (position < this.offsets[i]) {
return i - 1;
}
}
return this.total - 1;
}
offset(rowIndex) {
return this.offsets[rowIndex];
}
totalHeight() {
if (!this.offsets.length) {
return 0;
}
const lastOffset = this.offsets[this.offsets.length - 1];
const lastHeight = this.heights[this.heights.length - 1];
return lastOffset + lastHeight;
}
update(startIndex, rowHeights) {
let agg = this.offsets[startIndex];
for (let i = startIndex; i < this.heights.length; i++) {
this.offsets[i] = agg;
const currHeight = rowHeights[i - startIndex] || this.heights[i];
agg += currHeight;
this.heights[i] = currHeight;
}
}
}