Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export abstract class IgxForOfToken<T, U extends T[] = T[]> {

public abstract chunkLoad: EventEmitter<IForOfState>;
public abstract chunkPreload: EventEmitter<IForOfState>;
public abstract chunkSizeChange: EventEmitter<number>;

public abstract scrollTo(index: number): void;
public abstract getScrollForIndex(index: number, bottom?: boolean): number;
Expand Down Expand Up @@ -203,6 +204,13 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
@Output()
public scrollbarVisibilityChanged = new EventEmitter<any>();

/**
* @hidden @internal
* An event that is emitted when chunk size is changing. Emits new value.
*/
@Output()
public chunkSizeChange = new EventEmitter<number>();

/**
* An event that is emitted after the rendered content size of the igxForOf has been changed.
*/
Expand Down Expand Up @@ -1453,6 +1461,9 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
*/
protected applyChunkSizeChange() {
const chunkSize = this.isRemote ? (this.igxForOf ? this.igxForOf.length : 0) : this._calculateChunkSize();
if (chunkSize !== this.state.chunkSize) {
this.chunkSizeChange.emit(chunkSize);
}
if (chunkSize > this.state.chunkSize) {
const diff = chunkSize - this.state.chunkSize;
for (let i = 0; i < diff; i++) {
Expand Down
32 changes: 26 additions & 6 deletions projects/igniteui-angular/grids/grid/src/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
onResourceChangeHandle
} from 'igniteui-angular/core';
import { IgcTrialWatermark } from 'igniteui-trial-watermark';
import { Subject, pipe, fromEvent, animationFrameScheduler, merge } from 'rxjs';
import { takeUntil, first, filter, throttleTime, map, shareReplay, takeWhile } from 'rxjs/operators';
import { Subject, pipe, fromEvent, animationFrameScheduler, merge, BehaviorSubject, timer } from 'rxjs';
import { takeUntil, first, filter, throttleTime, map, shareReplay, takeWhile, throttle, take, switchMap } from 'rxjs/operators';
import {
IgxToggleDirective,
IForOfDataChangeEventArgs,
Expand All @@ -116,8 +116,8 @@
* Injection token for setting the throttle time used in grid virtual scroll.
* @hidden
*/
export const SCROLL_THROTTLE_TIME = /*@__PURE__*/new InjectionToken<number>('SCROLL_THROTTLE_TIME', {
factory: () => 40
export const SCROLL_THROTTLE_TIME_MULTIPLIER = /*@__PURE__*/new InjectionToken<number>('SCROLL_THROTTLE_TIME', {
factory: () => 10
});


Expand Down Expand Up @@ -177,7 +177,8 @@
protected _diTransactions = inject(IgxGridTransaction, { optional: true });
/** @hidden @internal */
public i18nFormatter = inject(I18N_FORMATTER);
private readonly THROTTLE_TIME = inject(SCROLL_THROTTLE_TIME);
private readonly THROTTLE_TIME_MULTIPLIER = inject(SCROLL_THROTTLE_TIME_MULTIPLIER);
private throttleTime$ = new BehaviorSubject<number>(this.THROTTLE_TIME_MULTIPLIER);

/**
* Gets/Sets the display time for the row adding snackbar notification.
Expand Down Expand Up @@ -3731,7 +3732,12 @@

this.scrollNotify.pipe(
filter(() => !this._init),
throttleTime(this.THROTTLE_TIME, animationFrameScheduler, { leading: false, trailing: true }),
throttle(() =>
this.throttleTime$.pipe(
take(1),
switchMap(time => timer(time, animationFrameScheduler))
)
),
destructor
)
.subscribe((event) => {
Expand Down Expand Up @@ -3822,6 +3828,14 @@
this.updateMergedData();
});

this.verticalScrollContainer.chunkSizeChange.pipe(destructor).subscribe((count: number) => {
this.updateScrollThrottle(count * this.headerContainer.state.chunkSize);
});

this.headerContainer.chunkSizeChange.pipe(destructor).subscribe((count: number) => {
this.updateScrollThrottle(count * this.verticalScrollContainer.state.chunkSize);
});

this.verticalScrollContainer.scrollbarVisibilityChanged.pipe(filter(() => !this._init), destructor).subscribe(() => {
// called to recalc all widths that may have changes as a result of
// the vert. scrollbar showing/hiding
Expand Down Expand Up @@ -3969,6 +3983,12 @@
return this._mergedDataInView;
}

protected updateScrollThrottle(cells: number) {
// for less than 100 no throttle, 10ms more for every 100 cells
const throttle = cells <= 100 ? 0 : Math.floor(cells / 100) * this.THROTTLE_TIME_MULTIPLIER;

Check failure on line 3988 in projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

View workflow job for this annotation

GitHub Actions / run-tests (22.x)

'throttle' is already declared in the upper scope on line 98 column 79

Check failure on line 3988 in projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

View workflow job for this annotation

GitHub Actions / run-tests (20.x)

'throttle' is already declared in the upper scope on line 98 column 79
this.throttleTime$.next(throttle);
}

/**
* @hidden
* @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed, fakeAsync, tick, ComponentFixture, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { IgxGridComponent } from './public_api';
import { SCROLL_THROTTLE_TIME } from './../src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../src/grid-base.directive';
import {
SelectionWithScrollsComponent,
SelectionWithTransactionsComponent,
Expand Down Expand Up @@ -980,7 +980,7 @@ describe('IgxGrid - Cell selection #grid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fix = TestBed.createComponent(SelectionWithScrollsComponent);
fix.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { DebugElement, QueryList } from '@angular/core';
import { IgxGridGroupByRowComponent } from './groupby-row.component';
import { CellType } from 'igniteui-angular/grids/core';
import { DefaultSortingStrategy, SortingDirection } from 'igniteui-angular/core';
import { SCROLL_THROTTLE_TIME } from './../src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../src/grid-base.directive';

const DEBOUNCETIME = 100;

Expand Down Expand Up @@ -224,7 +224,7 @@ describe('IgxGrid - Keyboard navigation #grid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fix = TestBed.createComponent(VirtualGridComponent);
fix.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GridFunctions, GRID_MRL_BLOCK } from '../../../test-utils/grid-function
import { CellType, IGridCellEventArgs, IgxColumnComponent, IgxGridMRLNavigationService } from 'igniteui-angular/grids/core';
import { IgxColumnLayoutComponent } from 'igniteui-angular/grids/core';
import { DefaultSortingStrategy, SortingDirection } from 'igniteui-angular/core';
import { SCROLL_THROTTLE_TIME } from './../src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../src/grid-base.directive';

const DEBOUNCE_TIME = 60;
const CELL_CSS_CLASS = '.igx-grid__td';
Expand All @@ -30,7 +30,7 @@ describe('IgxGrid Multi Row Layout - Keyboard navigation #grid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fix = TestBed.createComponent(ColumnLayoutTestComponent);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AsyncPipe } from '@angular/common';
import { setElementSize, ymd } from '../../../test-utils/helper-utils.spec';
import { FilteringExpressionsTree, FilteringLogic, getComponentSize, GridColumnDataType, IgxNumberFilteringOperand, IgxStringFilteringOperand, ISortingExpression, ɵSize, SortingDirection } from 'igniteui-angular/core';
import { IgxPaginatorComponent, IgxPaginatorContentDirective } from 'igniteui-angular/paginator';
import { SCROLL_THROTTLE_TIME } from './../src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../src/grid-base.directive';

describe('IgxGrid Component Tests #grid', () => {
const MIN_COL_WIDTH = '136px';
Expand All @@ -44,7 +44,7 @@ describe('IgxGrid Component Tests #grid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { GridSummaryCalculationMode, IgxStringFilteringOperand, SortingDirection
import { IgxCheckboxComponent } from 'igniteui-angular/checkbox';
import { IgxInputDirective, IgxInputGroupComponent } from 'igniteui-angular/input-group';
import { IgxPaginatorComponent } from 'igniteui-angular/paginator';
import { SCROLL_THROTTLE_TIME } from './../src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../src/grid-base.directive';

const DEBOUNCE_TIME = 60;
const ROW_TAG = 'igx-grid-row';
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('IgxGrid Master Detail #grid', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { clearGridSubs, setupHierarchicalGridScrollDetection } from '../../../te
import { GridFunctions } from '../../../test-utils/grid-functions.spec';
import { IGridCellEventArgs, IgxColumnComponent, IgxGridCellComponent, IgxGridNavigationService } from 'igniteui-angular/grids/core';
import { IPathSegment } from 'igniteui-angular/core';
import { SCROLL_THROTTLE_TIME } from './../../grid/src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../../grid/src/grid-base.directive';

const DEBOUNCE_TIME = 60;
const GRID_CONTENT_CLASS = '.igx-grid__tbody-content';
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('IgxHierarchicalGrid Navigation', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
}));

Expand All @@ -50,7 +50,7 @@ describe('IgxHierarchicalGrid Navigation', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fixture = TestBed.createComponent(IgxHierarchicalGridTestBaseComponent);
fixture.detectChanges();
Expand Down Expand Up @@ -965,7 +965,7 @@ describe('IgxHierarchicalGrid Navigation', () => {
describe('IgxHierarchicalGrid Navigation API #hGrid', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 1 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 1 }]
});
fixture = TestBed.createComponent(IgxHierarchicalGridMultiLayoutComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IgxHierarchicalGridDefaultComponent } from '../../../test-utils/hierarc
import { firstValueFrom } from 'rxjs';
import { FilteringExpressionsTree, FilteringLogic, IgxStringFilteringOperand } from 'igniteui-angular/core';
import { IgxGridNavigationService } from 'igniteui-angular/grids/core';
import { SCROLL_THROTTLE_TIME } from './../../grid/src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../../grid/src/grid-base.directive';

describe('IgxHierarchicalGrid Virtualization #hGrid', () => {
let fixture;
Expand All @@ -35,7 +35,7 @@ describe('IgxHierarchicalGrid Virtualization #hGrid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 1 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 1 }]
});
fixture = TestBed.createComponent(IgxHierarchicalGridTestBaseComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GridFunctions } from '../../../test-utils/grid-functions.spec';
import { DebugElement } from '@angular/core';
import { firstValueFrom } from 'rxjs';
import { CellType } from 'igniteui-angular/grids/core';
import { SCROLL_THROTTLE_TIME } from './../../grid/src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../../grid/src/grid-base.directive';

const DEBOUNCETIME = 60;

Expand Down Expand Up @@ -398,7 +398,7 @@ describe('IgxTreeGrid - Key Board Navigation #tGrid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fix = TestBed.createComponent(IgxTreeGridWithScrollsComponent);
fix.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { UIInteractions, wait } from '../../../test-utils/ui-interactions.spec';
import { GridSelectionFunctions, GridSummaryFunctions, GridFunctions } from '../../../test-utils/grid-functions.spec';
import { GridSelectionMode } from 'igniteui-angular/grids/core';
import { IgxStringFilteringOperand } from 'igniteui-angular/core';
import { SCROLL_THROTTLE_TIME } from './../../grid/src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../../grid/src/grid-base.directive';

describe('IgxTreeGrid - Multi Cell selection #tGrid', () => {

Expand All @@ -34,7 +34,7 @@ describe('IgxTreeGrid - Multi Cell selection #tGrid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 1 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 1 }]
});
fix = TestBed.createComponent(IgxTreeGridSelectionKeyComponent);
fix.detectChanges();
Expand Down Expand Up @@ -561,7 +561,7 @@ describe('IgxTreeGrid - Multi Cell selection #tGrid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fix = TestBed.createComponent(IgxTreeGridSelectionComponent);
fix.detectChanges();
Expand Down Expand Up @@ -676,7 +676,7 @@ describe('IgxTreeGrid - Multi Cell selection #tGrid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fix = TestBed.createComponent(IgxTreeGridSelectionWithTransactionComponent);
fix.detectChanges();
Expand Down Expand Up @@ -809,7 +809,7 @@ describe('IgxTreeGrid - Multi Cell selection #tGrid', () => {

beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
fix = TestBed.createComponent(IgxTreeGridFKeySelectionWithTransactionComponent);
fix.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { DebugElement } from '@angular/core';
import { IgxTreeGridComponent } from './tree-grid.component';
import { IgxSummaryRow, IgxTreeGridRow } from 'igniteui-angular/grids/core';
import { IgxNumberFilteringOperand } from 'igniteui-angular/core';
import { SCROLL_THROTTLE_TIME } from './../../grid/src/grid-base.directive';
import { SCROLL_THROTTLE_TIME_MULTIPLIER } from './../../grid/src/grid-base.directive';

describe('IgxTreeGrid - Summaries #tGrid', () => {
const DEBOUNCETIME = 30;
Expand All @@ -36,7 +36,7 @@ describe('IgxTreeGrid - Summaries #tGrid', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
providers: [{ provide: SCROLL_THROTTLE_TIME, useValue: 0 }]
providers: [{ provide: SCROLL_THROTTLE_TIME_MULTIPLIER, useValue: 0 }]
});
}));

Expand Down
Loading