Skip to content

Commit 6f5b5f7

Browse files
committed
feat(igxTreeGrid): Adds pipe to modify data for a shadow row #6640
1 parent 32d3b36 commit 6f5b5f7

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@
7878
<ng-template #pinnedRecordsTemplate>
7979
<ng-container *ngFor="let rowData of data
8080
| visibleColumns:hasVisibleColumns
81-
| treeGridRowPinning:id:true:pipeTrigger
81+
| treeGridRowPinning:id:pipeTrigger
8282
| treeGridHierarchizing:primaryKey:foreignKey:childDataKey:id:pipeTrigger
8383
| treeGridFiltering:filteringExpressionsTree:filterStrategy:advancedFilteringExpressionsTree:id:pipeTrigger:filteringPipeTrigger
84-
| treeGridPinnedRows:id:pipeTrigger
8584
| treeGridSorting:sortingExpressions:sortStrategy:id:pipeTrigger; let rowIndex = index">
8685
<ng-container *ngTemplateOutlet="record_template; context: getContext(rowData, rowIndex, true)">
8786
</ng-container>
@@ -94,8 +93,8 @@
9493
<ng-template igxGridFor let-rowData [igxGridForOf]="data
9594
| treeGridTransaction:id:pipeTrigger
9695
| visibleColumns:hasVisibleColumns
97-
| treeGridRowPinning:id:false:pipeTrigger
9896
| treeGridHierarchizing:primaryKey:foreignKey:childDataKey:id:pipeTrigger
97+
| treeGridShadowRows:id:pipeTrigger
9998
| treeGridFiltering:filteringExpressionsTree:filterStrategy:advancedFilteringExpressionsTree:id:pipeTrigger:filteringPipeTrigger
10099
| treeGridSorting:sortingExpressions:sortStrategy:id:pipeTrigger
101100
| treeGridFlattening:id:expansionDepth:expansionStates:pipeTrigger

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
22
import { IgxTreeGridComponent } from './tree-grid.component';
33
import { IgxTreeGridRowComponent } from './tree-grid-row.component';
44
import { IgxGridCommonModule } from '../grid-common.module';
5-
import { IgxTreeGridHierarchizingPipe, IgxTreeGridRowPinningPipe, IgxTreeGridPinnedRowsPipe } from './tree-grid.pipes';
5+
import { IgxTreeGridHierarchizingPipe, IgxTreeGridRowPinningPipe, IgxTreeGridShadowRowsPipe } from './tree-grid.pipes';
66
import { IgxTreeGridFlatteningPipe, IgxTreeGridSortingPipe, IgxTreeGridPagingPipe, IgxTreeGridTransactionPipe } from './tree-grid.pipes';
77
import { IgxTreeGridCellComponent } from './tree-cell.component';
88
import { IgxTreeGridFilteringPipe } from './tree-grid.filtering.pipe';
@@ -26,7 +26,7 @@ import { IgxRowLoadingIndicatorTemplateDirective } from './tree-grid.directives'
2626
IgxTreeGridSummaryPipe,
2727
IgxRowLoadingIndicatorTemplateDirective,
2828
IgxTreeGridRowPinningPipe,
29-
IgxTreeGridPinnedRowsPipe
29+
IgxTreeGridShadowRowsPipe
3030
],
3131
exports: [
3232
IgxTreeGridComponent,

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,28 +324,27 @@ export class IgxTreeGridRowPinningPipe implements PipeTransform {
324324
this.gridAPI = <IgxTreeGridAPIService> gridAPI;
325325
}
326326

327-
transform(collection: any[], id: string, isPinned = false, pipeTrigger: number): any[] {
327+
transform(collection: any[], id: string, pipeTrigger: number): any[] {
328328
const grid = this.gridAPI.grid;
329329

330330
if (!grid.hasPinnedRecords) {
331-
return isPinned ? [] : collection;
331+
return [];
332332
}
333333

334-
const result = (isPinned) ? collection.filter((value, index) => grid.isRecordPinned(value)) : collection;
334+
const result = collection.filter((value, index) => grid.isRecordPinned(value));
335+
336+
// pinned records should be ordered as they were pinned.
337+
result.sort((rec1, rec2) => grid.pinRecordIndex(rec1) - grid.pinRecordIndex(rec2));
335338

336-
if (isPinned) {
337-
// pinned records should be ordered as they were pinned.
338-
result.sort((rec1, rec2) => grid.pinRecordIndex(rec1) - grid.pinRecordIndex(rec2));
339-
}
340339
return result;
341340
}
342341
}
343342

344343
@Pipe({
345-
name: 'treeGridPinnedRows',
344+
name: 'treeGridShadowRows',
346345
pure: true
347346
})
348-
export class IgxTreeGridPinnedRowsPipe implements PipeTransform {
347+
export class IgxTreeGridShadowRowsPipe implements PipeTransform {
349348

350349
private gridAPI: IgxTreeGridAPIService;
351350

@@ -354,7 +353,24 @@ export class IgxTreeGridPinnedRowsPipe implements PipeTransform {
354353
}
355354

356355
transform(collection: any[], id: string, pipeTrigger: number): any[] {
356+
357+
this.modifyPinnedRecordsIDs(collection);
358+
357359
return collection;
358360
}
359361

362+
private modifyPinnedRecordsIDs(records: ITreeGridRecord[]) {
363+
if (records && records.length) {
364+
records.map((value, idx) => {
365+
if (this.gridAPI.grid.isRecordPinned(value.data)) {
366+
// Modify the rowID in order to make a recognizeable shadow row
367+
// value.rowID += "_shadow";
368+
}
369+
if (value.children) {
370+
this.modifyPinnedRecordsIDs(value.children);
371+
}
372+
});
373+
}
374+
}
375+
360376
}

0 commit comments

Comments
 (0)