Skip to content

Commit 8912f31

Browse files
committed
feat(igxTreeGrid): Initial commit of tree grid's row pinning #6640
1 parent ff2e0f6 commit 8912f31

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,29 @@
7575
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length > 0"
7676
[igxColumnMovingDrop]="headerContainer" [attr.droppable]="true" id="left"
7777
class="igx-grid__scroll-on-drag-pinned" [style.left.px]="pinnedWidth"></span>
78+
<ng-template #pinnedRecordsTemplate>
79+
<ng-container *ngFor="let rowData of pinnedRecords
80+
| visibleColumns:hasVisibleColumns
81+
| treeGridFiltering:filteringExpressionsTree:filterStrategy:advancedFilteringExpressionsTree:id:pipeTrigger:filteringPipeTrigger
82+
| treeGridPinnedRows:id:pipeTrigger
83+
| treeGridSorting:sortingExpressions:sortStrategy:id:pipeTrigger; let rowIndex = index">
84+
<ng-template #record_template let-rowIndex="index">
85+
<igx-tree-grid-row [gridID]="id" [index]="rowIndex" [treeRow]="rowData" #row>
86+
</igx-tree-grid-row>
87+
</ng-template>
88+
<ng-container [igxTemplateOutlet]="record_template" [igxTemplateOutletContext]="getContext(rowData, rowIndex)">
89+
</ng-container>
90+
</ng-container>
91+
</ng-template>
92+
<div #pinContainer *ngIf='pinnedRecords.length > 0 && isRowPinningToTop' class='igx-grid__tr--pinned igx-grid__tr--pinned-top'>
93+
<ng-container *ngTemplateOutlet="pinnedRecordsTemplate">
94+
</ng-container>
95+
</div>
7896
<ng-template igxGridFor let-rowData
7997
[igxGridForOf]="data
8098
| treeGridTransaction:id:pipeTrigger
8199
| visibleColumns:hasVisibleColumns
100+
| treeGridRowPinning:id:pipeTrigger
82101
| treeGridHierarchizing:primaryKey:foreignKey:childDataKey:id:pipeTrigger
83102
| treeGridFiltering:filteringExpressionsTree:filterStrategy:advancedFilteringExpressionsTree:id:pipeTrigger:filteringPipeTrigger
84103
| treeGridSorting:sortingExpressions:sortStrategy:id:pipeTrigger

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,56 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
526526
}
527527
}
528528

529+
/**
530+
* Pin the row by its id.
531+
* @remarks
532+
* ID is either the primaryKey value or the data record instance.
533+
* @example
534+
* ```typescript
535+
* this.grid.pinRow(rowID);
536+
* ```
537+
* @param rowID The row id - primaryKey value or the data record instance.
538+
* @param index The index at which to insert the row in the pinned collection.
539+
*/
540+
public pinRow(rowID, index?): boolean {
541+
const rec = this.gridAPI.get_rec_by_id(rowID);
542+
const flattenedRecord = {...rec};
543+
flattenedRecord.children = [];
544+
flattenedRecord.level = 0;
545+
546+
if (!rec || this.isRowInPinnedRecordsStructure(rec) || this.flatData.indexOf(rec.data) === -1) {
547+
return false;
548+
}
549+
const row = this.gridAPI.get_row_by_key(rowID);
550+
551+
const eventArgs = {
552+
insertAtIndex: index,
553+
isPinned: true,
554+
rowID: rowID,
555+
row: row
556+
};
557+
this.onRowPinning.emit(eventArgs);
558+
559+
this.pinnedRecords.splice(eventArgs.insertAtIndex || this.pinnedRecords.length, 0, flattenedRecord);
560+
this._pipeTrigger++;
561+
if (this.gridAPI.grid) {
562+
this.notifyChanges(true);
563+
}
564+
}
565+
566+
/**
567+
* @hidden @internal
568+
*/
569+
private isRowInPinnedRecordsStructure(rec: ITreeGridRecord): boolean {
570+
let inStructure = false;
571+
this.pinnedRecords.forEach(pinnedRecord => {
572+
if (JSON.stringify(pinnedRecord.data) === JSON.stringify(rec.data)) {
573+
inStructure = true;
574+
}
575+
});
576+
return inStructure;
577+
}
578+
529579
/** @hidden */
530580
public deleteRowById(rowId: any) {
531581
// if this is flat self-referencing data, and CascadeOnDelete is set to true

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

Lines changed: 4 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 } from './tree-grid.pipes';
5+
import { IgxTreeGridHierarchizingPipe, IgxTreeGridRowPinningPipe, IgxTreeGridPinnedRowsPipe } 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';
@@ -24,7 +24,9 @@ import { IgxRowLoadingIndicatorTemplateDirective } from './tree-grid.directives'
2424
IgxTreeGridPagingPipe,
2525
IgxTreeGridTransactionPipe,
2626
IgxTreeGridSummaryPipe,
27-
IgxRowLoadingIndicatorTemplateDirective
27+
IgxRowLoadingIndicatorTemplateDirective,
28+
IgxTreeGridRowPinningPipe,
29+
IgxTreeGridPinnedRowsPipe
2830
],
2931
exports: [
3032
IgxTreeGridComponent,

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,38 @@ export class IgxTreeGridTransactionPipe implements PipeTransform {
307307
return collection;
308308
}
309309
}
310+
311+
@Pipe({
312+
name: 'treeGridRowPinning',
313+
pure: true
314+
})
315+
export class IgxTreeGridRowPinningPipe implements PipeTransform {
316+
317+
private gridAPI: IgxTreeGridAPIService;
318+
319+
constructor(gridAPI: GridBaseAPIService<IgxGridBaseDirective & GridType>) {
320+
this.gridAPI = <IgxTreeGridAPIService> gridAPI;
321+
}
322+
323+
transform(collection: any[], id: string, pipeTrigger: number): any[] {
324+
return collection;
325+
}
326+
}
327+
328+
@Pipe({
329+
name: 'treeGridPinnedRows',
330+
pure: true
331+
})
332+
export class IgxTreeGridPinnedRowsPipe implements PipeTransform {
333+
334+
private gridAPI: IgxTreeGridAPIService;
335+
336+
constructor(gridAPI: GridBaseAPIService<IgxGridBaseDirective & GridType>) {
337+
this.gridAPI = <IgxTreeGridAPIService> gridAPI;
338+
}
339+
340+
transform(collection: any[], id: string, pipeTrigger: number): any[] {
341+
return collection;
342+
}
343+
344+
}

0 commit comments

Comments
 (0)