Skip to content

Commit 6507d5b

Browse files
authored
perf(grid): Improved data view performance (#10630)
1 parent c2bade6 commit 6507d5b

File tree

6 files changed

+48
-40
lines changed

6 files changed

+48
-40
lines changed

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
826826
*/
827827
public pointerenter = (event: PointerEvent) => {
828828
const isHierarchicalGrid = this.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
829-
if (isHierarchicalGrid && (!this.grid.navigation.activeNode.gridID || this.grid.navigation.activeNode.gridID !== this.gridID)) {
829+
if (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID || this.grid.navigation.activeNode.gridID !== this.gridID)) {
830830
return;
831831
}
832832
const dragMode = this.selectionService.pointerEnter(this.selectionNode, event);
@@ -841,7 +841,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
841841
*/
842842
public pointerup = (event: PointerEvent) => {
843843
const isHierarchicalGrid = this.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
844-
if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation.activeNode.gridID ||
844+
if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
845845
this.grid.navigation.activeNode.gridID !== this.gridID))) {
846846
return;
847847
}

projects/igniteui-angular/src/lib/grids/columns/column-group.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
371371
});
372372
}
373373
}
374-
// constructor(public gridAPI: GridBaseAPIService<IgxGridBaseDirective & IGridDataBindable>, public cdr: ChangeDetectorRef) {
375-
// // D.P. constructor duplication due to es6 compilation, might be obsolete in the future
376-
// super(gridAPI, cdr);
377-
// }
378374

379375
/**
380376
* @hidden

projects/igniteui-angular/src/lib/grids/common/pipes.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ export class IgxHasVisibleColumnsPipe implements PipeTransform {
233233

234234
}
235235

236+
/** @hidden @internal */
237+
function buildDataView(): MethodDecorator {
238+
return function (_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) {
239+
const original = descriptor.value;
240+
descriptor.value = function (...args: unknown[]) {
241+
const result = original.apply(this, args);
242+
this.grid.buildDataView();
243+
return result;
244+
}
245+
return descriptor;
246+
}
247+
}
248+
236249
/**
237250
* @hidden
238251
*/
@@ -241,6 +254,7 @@ export class IgxGridRowPinningPipe implements PipeTransform {
241254

242255
constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
243256

257+
@buildDataView()
244258
public transform(collection: any[], id: string, isPinned = false, _pipeTrigger: number) {
245259

246260
if (this.grid.hasPinnedRecords && isPinned) {

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
11591159
}
11601160

11611161
public get headerSelectorContainer() {
1162-
return this.theadRow?.headerSelectorContainer;
1162+
return this.theadRow?.headerSelectorContainer;
11631163
}
11641164

11651165
public get headerDragContainer() {
@@ -2761,6 +2761,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
27612761
private _visibleColumns = [];
27622762
private _columnGroups = false;
27632763
private _autoGeneratedCols = [];
2764+
private _dataView = [];
27642765

27652766
private _columnWidth: string;
27662767

@@ -3237,7 +3238,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
32373238
this.onDensityChanged.pipe(destructor).subscribe(() => {
32383239
this.crudService.endEdit(false);
32393240
if (this._summaryRowHeight === 0) {
3240-
this.summaryService.summaryHeight = 0;
3241+
this.summaryService.summaryHeight = 0;
32413242
}
32423243
this.notifyChanges(true);
32433244
});
@@ -3430,18 +3431,21 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
34303431
*/
34313432
public setFilteredSortedData(data, pinned: boolean) {
34323433
data = data || [];
3433-
if (this.pinnedRecordsCount > 0 && pinned) {
3434-
this._filteredSortedPinnedData = data;
3435-
this.pinnedRecords = data;
3436-
this._filteredSortedData = this.isRowPinningToTop ? [... this._filteredSortedPinnedData, ... this._filteredSortedUnpinnedData] :
3437-
[... this._filteredSortedUnpinnedData, ... this._filteredSortedPinnedData];
3438-
this.refreshSearch(true, false);
3439-
} else if (this.pinnedRecordsCount > 0 && !pinned) {
3440-
this._filteredSortedUnpinnedData = data;
3434+
if (this.pinnedRecordsCount > 0) {
3435+
if (pinned) {
3436+
this._filteredSortedPinnedData = data;
3437+
this.pinnedRecords = data;
3438+
this._filteredSortedData = this.isRowPinningToTop ? [... this._filteredSortedPinnedData, ... this._filteredSortedUnpinnedData] :
3439+
[... this._filteredSortedUnpinnedData, ... this._filteredSortedPinnedData];
3440+
this.refreshSearch(true, false);
3441+
} else {
3442+
this._filteredSortedUnpinnedData = data;
3443+
}
34413444
} else {
34423445
this._filteredSortedData = data;
34433446
this.refreshSearch(true, false);
34443447
}
3448+
this.buildDataView();
34453449
}
34463450

34473451
/**
@@ -5115,10 +5119,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
51155119
* const dataView = this.grid.dataView;
51165120
* ```
51175121
*/
5118-
public get dataView(): any[] {
5119-
return this.isRowPinningToTop ?
5120-
[...this.pinnedDataView, ...this.unpinnedDataView] :
5121-
[...this.unpinnedDataView, ...this.pinnedDataView];
5122+
public get dataView() {
5123+
return this._dataView;
51225124
}
51235125

51245126
/**
@@ -6911,6 +6913,12 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
69116913
column.resetCaches();
69126914
}
69136915

6916+
private buildDataView() {
6917+
this._dataView = this.isRowPinningToTop ?
6918+
[...this.pinnedDataView, ...this.unpinnedDataView] :
6919+
[...this.unpinnedDataView, ...this.pinnedDataView];
6920+
}
6921+
69146922
private _applyWidthHostBinding() {
69156923
let width = this._width;
69166924
if (width === null) {

projects/igniteui-angular/src/lib/grids/grid/grid.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<div class="igx-grid__row-indentation igx-grid__row-indentation--level-{{groupingExpressions.length}}"></div>
125125
</ng-container>
126126
<ng-template
127-
[ngTemplateOutlet]='detailTemplate'
127+
[ngTemplateOutlet]='detailTemplate.first'
128128
[ngTemplateOutletContext]='getDetailsContext(rowData, rowIndex)'>
129129
</ng-template>
130130
</div>

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
150150
/**
151151
* @hidden @internal
152152
*/
153-
@ContentChild(IgxGridDetailTemplateDirective, { read: TemplateRef, static: false })
154-
public detailTemplate: TemplateRef<any> = null;
153+
@ContentChildren(IgxGridDetailTemplateDirective, { read: TemplateRef })
154+
public detailTemplate: QueryList<TemplateRef<any>> = new QueryList();
155155

156156
/**
157157
* @hidden @internal
@@ -200,12 +200,6 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
200200
@ContentChild(IgxGroupByRowTemplateDirective, { read: IgxGroupByRowTemplateDirective })
201201
protected groupTemplate: IgxGroupByRowTemplateDirective;
202202

203-
/**
204-
* @hidden @internal
205-
*/
206-
@ContentChild(IgxGridDetailTemplateDirective, { read: IgxGridDetailTemplateDirective, static: false })
207-
protected gridDetailsTemplate: IgxGridDetailTemplateDirective;
208-
209203
/**
210204
* @hidden
211205
* @internal
@@ -555,16 +549,6 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
555549
};
556550
}
557551

558-
/**
559-
* @hidden @internal
560-
*/
561-
public trackChanges(index, rec) {
562-
if (rec && rec.detailsData !== undefined) {
563-
return rec.detailsData;
564-
}
565-
return rec;
566-
}
567-
568552
/**
569553
* @hidden @internal
570554
*/
@@ -576,7 +560,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
576560
* @hidden @internal
577561
*/
578562
public get hasDetails() {
579-
return !!this.gridDetailsTemplate;
563+
return !!this.detailTemplate.length;
580564
}
581565

582566
/**
@@ -645,6 +629,9 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
645629
this.notifyChanges();
646630
}
647631

632+
/** @hidden @internal */
633+
public trackChanges: (index, rec) => any;
634+
648635
/**
649636
* Groups by a new `IgxColumnComponent` based on the provided expression, or modifies an existing one.
650637
*
@@ -938,6 +925,9 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
938925
this._groupRowTemplate = this.groupTemplate.template;
939926
}
940927

928+
this.detailTemplate.changes.subscribe(() =>
929+
this.trackChanges = (_, rec) => (rec?.detailsData !== undefined ? rec.detailsData : rec));
930+
941931
if (this.hideGroupedColumns && this.columnList && this.groupingExpressions) {
942932
this._setGroupColsVisibility(this.hideGroupedColumns);
943933
}

0 commit comments

Comments
 (0)