virtual scrolling +

This commit is contained in:
Mohaimen Hasan 2026-11-15 13:49:48 +06:00
parent 75e94ddc94
commit ad8031c3a4
3 changed files with 64 additions and 7 deletions

View File

@ -167,6 +167,13 @@ kendo-numerictextbox{
border-top: 1px solid #e9ecef;
}
/* virtual scrolling needs every row the same height ([rowHeight]="40"): 32px inputs + 4px padding */
:host ::ng-deep .adp-emp-grid .k-grid-content td {
height: 40px;
padding-top: 4px;
padding-bottom: 4px;
}
.adp-sum {
font-weight: bold;
}

View File

@ -457,8 +457,18 @@
</div>
</div>
<kendo-grid [data]="_individualEmplyees"
<!-- <kendo-grid [data]="_individualEmplyees"
height="300"
(remove)="removeHandler($event)"> -->
<!-- virtual scrolling: only the rows on screen are built (empGridView = a window of _individualEmplyees) -->
<kendo-grid [data]="empGridView"
class="adp-emp-grid"
[height]="360"
scrollable="virtual"
[rowHeight]="40"
[skip]="empGridSkip"
[pageSize]="empGridPageSize"
(pageChange)="onEmpGridPageChange($event)"
(remove)="removeHandler($event)">
<kendo-grid-column field="employeeNo" title="Emp ID">
</kendo-grid-column>

View File

@ -1,4 +1,5 @@
import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core';
import {Component, OnInit, ChangeDetectionStrategy, DoCheck} from '@angular/core';
import { GridDataResult, PageChangeEvent } from '@progress/kendo-angular-grid';
import {FormGroup, FormControl, FormBuilder, Validators} from '@angular/forms';
import {SearchEmployee} from '../../../../_models/Employee/searchEmployee';
import {AdparameterService} from '../../../../_services/payroll/adparameter.service';
@ -34,7 +35,7 @@ import { EmployeePickerComponent } from 'src/app/picker/employee-picker.componen
standalone: false,
})
export class AllowanceDeductionParameterizationEntryComponent implements OnInit {
export class AllowanceDeductionParameterizationEntryComponent implements OnInit, DoCheck {
_adPram: ADParameter;
_allowDeducts: AllowanceDeduction[];
_grades: Grade[];
@ -363,7 +364,6 @@ export class AllowanceDeductionParameterizationEntryComponent implements OnInit
}
public Save() {
debugger;
if (this._fromValidator.invalid) {
return;
}
@ -389,7 +389,6 @@ export class AllowanceDeductionParameterizationEntryComponent implements OnInit
}
if (this._adPram.adParameterEmployees.length > 0) {
this._adPram.adParameterEmployees.forEach(x => {
debugger;
let adParamEmpItem: ADParameterEmployee = this.prADParameterEmployees.find(y => y.id === x.id);
let oPayrollType: PayrollType = new PayrollType();
if (adParamEmpItem) {
@ -402,8 +401,6 @@ export class AllowanceDeductionParameterizationEntryComponent implements OnInit
x.oldTillDate = adParamEmpItem.tillDate;
}
}
});
}
debugger;
@ -451,6 +448,49 @@ export class AllowanceDeductionParameterizationEntryComponent implements OnInit
return parseFloat((value).toFixed(2));
}
//#region Employee grid: virtual scrolling (display only)
// The employee grid shows only the rows on screen (a window of empGridPageSize rows), so 12k-20k
// employees load at once. _individualEmplyees stays the one full list that every existing function
// (Add, Remove, Remove All, Sum, Save, tabs) works on; each window holds the same row objects, so an
// amount or date typed in the grid lands in that list exactly as before.
empGridView: GridDataResult = { data: [], total: 0 };
empGridSkip = 0;
empGridPageSize = 50;
private empGridSource: ADParameterEmployee[];
private empGridLength = -1;
/** Rebuilds the window when the list is replaced (tab change, load) or grows / shrinks (Add, Remove, Remove All). */
ngDoCheck(): void {
const list = this._individualEmplyees;
const length = list ? list.length : 0;
if (list !== this.empGridSource || length !== this.empGridLength) {
if (list !== this.empGridSource) {
this.empGridSkip = 0; // another list (tab): start from the top
}
this.empGridSource = list;
this.empGridLength = length;
this.loadEmpGridView();
}
}
/** The grid scrolled: show the rows of the new window. */
onEmpGridPageChange(event: PageChangeEvent): void {
this.empGridSkip = event.skip;
this.loadEmpGridView();
}
private loadEmpGridView(): void {
const list = this._individualEmplyees || [];
if (this.empGridSkip >= list.length) { // rows were removed below the current window
this.empGridSkip = Math.max(0, list.length - this.empGridPageSize);
}
this.empGridView = {
data: list.slice(this.empGridSkip, this.empGridSkip + this.empGridPageSize),
total: list.length
};
}
//#endregion
}