Skip to content

Commit a45ed20

Browse files
committed
feat(igxTreeGrid): Implements ghost row data modifications #6640
1 parent d627093 commit a45ed20

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export class IgxTreeGridCellComponent extends IgxGridExpandableCellComponent {
5050
@Input()
5151
showIndicator = false;
5252

53-
5453
/**
5554
* @hidden
5655
*/

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export class IgxTreeGridRowComponent extends IgxRowDirective<IgxTreeGridComponen
4040
public set treeRow(value: ITreeGridRecord) {
4141
if (this._treeRow !== value) {
4242
this._treeRow = value;
43-
this.rowData = this._treeRow.data;
43+
this.rowData = this.grid.isGhostRecord(this._treeRow.data) ?
44+
this._treeRow.data.recordData :
45+
this._treeRow.data;
4446
}
4547
}
4648

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
<ng-template igxGridFor let-rowData [igxGridForOf]="data
9999
| treeGridTransaction:id:pipeTrigger
100100
| visibleColumns:hasVisibleColumns
101-
| treeGridHierarchizing:primaryKey:foreignKey:childDataKey:id:pipeTrigger
102101
| treeGridShadowRows:id:pipeTrigger
102+
| treeGridHierarchizing:primaryKey:foreignKey:childDataKey:id:pipeTrigger
103103
| treeGridFiltering:filteringExpressionsTree:filterStrategy:advancedFilteringExpressionsTree:id:pipeTrigger:filteringPipeTrigger
104104
| treeGridSorting:sortingExpressions:sortStrategy:id:pipeTrigger
105105
| treeGridFlattening:id:expansionDepth:expansionStates:pipeTrigger

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
381381
private flattenTreeGridRecords(records: ITreeGridRecord[], flatData: any[]) {
382382
if (records && records.length) {
383383
for (const record of records) {
384-
flatData.push(record.data);
384+
(this.isGhostRecord(record)) ? flatData.push(record.data.recordData) : flatData.push(record.data);
385385
this.flattenTreeGridRecords(record.children, flatData);
386386
}
387387
}
@@ -642,6 +642,15 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
642642
};
643643
}
644644

645+
/**
646+
* Informs whether the record is a ghost, i.e. a pinned body instance.
647+
* @param record
648+
* @hidden @internal
649+
*/
650+
public isGhostRecord(record: any): boolean {
651+
return record.ghostRec !== undefined;
652+
}
653+
645654
/**
646655
* @inheritdoc
647656
*/

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.pipes.ts

+14-20
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ export class IgxTreeGridHierarchizingPipe implements PipeTransform {
5454
const result: ITreeGridRecord[] = [];
5555
const missingParentRecords: ITreeGridRecord[] = [];
5656
collection.forEach(row => {
57+
const ghostRow = row.ghostRec !== undefined;
5758
const record: ITreeGridRecord = {
58-
rowID: this.getRowID(primaryKey, row),
59+
rowID: ghostRow ? this.getRowID(primaryKey, row.recordData) : this.getRowID(primaryKey, row),
5960
data: row,
6061
children: []
6162
};
62-
const parent = map.get(row[foreignKey]);
63+
const parent = ghostRow ? map.get(row.recordData[foreignKey]) : map.get(row[foreignKey]);
6364
if (parent) {
6465
record.parent = parent;
6566
parent.children.push(record);
6667
} else {
6768
missingParentRecords.push(record);
6869
}
6970

70-
map.set(row[primaryKey], record);
71+
ghostRow ? map.set(row.recordData[primaryKey], record) :
72+
map.set(row[primaryKey], record);
7173
});
7274

7375
missingParentRecords.forEach(record => {
@@ -90,7 +92,7 @@ export class IgxTreeGridHierarchizingPipe implements PipeTransform {
9092
const record = collection[i];
9193
record.level = indentationLevel;
9294
record.expanded = this.gridAPI.get_row_expansion_state(record);
93-
flatData.push(record.data);
95+
this.gridAPI.grid.isGhostRecord(record.data) ? flatData.push(record.data.recordData) : flatData.push(record.data);
9496

9597
if (record.children && record.children.length > 0) {
9698
this.setIndentationLevels(id, record.children, indentationLevel + 1, flatData);
@@ -363,23 +365,15 @@ export class IgxTreeGridShadowRowsPipe implements PipeTransform {
363365

364366
transform(collection: any[], id: string, pipeTrigger: number): any[] {
365367

366-
this.modifyPinnedRecordsIDs(collection);
368+
const result = [];
367369

368-
return collection;
369-
}
370+
collection.forEach(value => {
371+
if (this.gridAPI.grid.isRecordPinned(value)) {
372+
value = { recordData: value, ghostRec: true };
373+
}
374+
result.push(value);
375+
});
370376

371-
private modifyPinnedRecordsIDs(records: ITreeGridRecord[]) {
372-
if (records && records.length) {
373-
records.map((value, idx) => {
374-
if (this.gridAPI.grid.isRecordPinned(value.data)) {
375-
// Modify the rowID in order to make a recognizeable shadow row
376-
// value.rowID += "_shadow";
377-
}
378-
if (value.children) {
379-
this.modifyPinnedRecordsIDs(value.children);
380-
}
381-
});
382-
}
377+
return result;
383378
}
384-
385379
}

0 commit comments

Comments
 (0)