Skip to content

Commit 05ab7df

Browse files
authored
Merge pull request #6936 from IgniteUI/pbozhinov/row-pinning-tree-grid
Row Pinning Tree Grid
2 parents 31abc2e + 2ff86d9 commit 05ab7df

20 files changed

+495
-101
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
IgxGridPaginatorOptionsPipe,
1111
IgxHasVisibleColumnsPipe,
1212
IgxDatePipeComponent,
13-
IgxDecimalPipeComponent
13+
IgxDecimalPipeComponent,
14+
IgxGridRowPinningPipe
1415
} from './pipes';
1516

1617
@NgModule({
@@ -24,7 +25,8 @@ import {
2425
IgxGridCellStylesPipe,
2526
IgxGridCellStyleClassesPipe,
2627
IgxGridPaginatorOptionsPipe,
27-
IgxHasVisibleColumnsPipe
28+
IgxHasVisibleColumnsPipe,
29+
IgxGridRowPinningPipe
2830
],
2931
exports: [
3032
IgxDatePipeComponent,
@@ -36,7 +38,8 @@ import {
3638
IgxGridCellStylesPipe,
3739
IgxGridCellStyleClassesPipe,
3840
IgxGridPaginatorOptionsPipe,
39-
IgxHasVisibleColumnsPipe
41+
IgxHasVisibleColumnsPipe,
42+
IgxGridRowPinningPipe
4043
],
4144
imports: [
4245
CommonModule

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,34 @@ export class IgxDecimalPipeComponent extends DecimalPipe implements PipeTransfor
212212
}
213213
}
214214
}
215+
216+
/**
217+
* @hidden
218+
*/
219+
@Pipe({
220+
name: 'gridRowPinning',
221+
pure: true
222+
})
223+
export class IgxGridRowPinningPipe implements PipeTransform {
224+
225+
constructor(private gridAPI: GridBaseAPIService<IgxGridBaseDirective & GridType>) {}
226+
227+
public transform(collection: any[] , id: string, isPinned = false, pipeTrigger: number) {
228+
const grid = this.gridAPI.grid;
229+
230+
if (!grid.hasPinnedRecords) {
231+
return isPinned ? [] : collection;
232+
}
233+
234+
if (grid.hasPinnedRecords && isPinned) {
235+
const result = collection.filter(rec => grid.isRecordPinned(rec));
236+
result.sort((rec1, rec2) => grid.pinRecordIndex(rec1) - grid.pinRecordIndex(rec2));
237+
return result;
238+
}
239+
240+
grid.unpinnedRecords = collection;
241+
return collection.map((rec) => {
242+
return grid.isRecordPinned(rec) ? { recordRef: rec, ghostRecord: true} : rec;
243+
});
244+
}
245+
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,8 +2930,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
29302930

29312931
public setFilterData(data, pinned: boolean) {
29322932
if (this.hasPinnedRecords && pinned) {
2933-
this._filteredPinnedData = data;
2934-
this.filteredData = [... this._filteredPinnedData, ... this._filteredUnpinnedData];
2933+
this._filteredPinnedData = data || [];
2934+
const filteredUnpinned = this._filteredUnpinnedData || [];
2935+
this.filteredData = [... this._filteredPinnedData, ... filteredUnpinned];
29352936
} else if (this.hasPinnedRecords && !pinned) {
29362937
this._filteredUnpinnedData = data;
29372938
} else {
@@ -2987,6 +2988,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
29872988
* @internal
29882989
*/
29892990
public setFilteredSortedData(data, pinned: boolean) {
2991+
data = data.map(rec => rec.ghostRecord !== undefined ? rec.recordRef : rec);
29902992
if (this._pinnedRecordIDs.length > 0 && pinned) {
29912993
this._filteredSortedPinnedData = data;
29922994
this.filteredSortedData = this.isRowPinningToTop ? [... this._filteredSortedPinnedData, ... this._filteredSortedUnpinnedData] :
@@ -5164,13 +5166,13 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
51645166
return this.unpinnedRecords ? this.unpinnedRecords : this.verticalScrollContainer.igxForOf;
51655167
}
51665168

5167-
/**
5168-
* Returns the currently transformed paged/filtered/sorted/grouped pinned data, displayed in the grid.
5169-
* @example
5170-
* ```typescript
5171-
* const pinnedDataView = this.grid.pinnedDataView;
5172-
* ```
5173-
*/
5169+
/**
5170+
* Returns the currently transformed paged/filtered/sorted/grouped pinned data, displayed in the grid.
5171+
* @example
5172+
* ```typescript
5173+
* const pinnedDataView = this.grid.pinnedDataView;
5174+
* ```
5175+
*/
51745176
get pinnedDataView(): any[] {
51755177
return this.pinnedRows.map(row => row.rowData);
51765178
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
IgxGridPagingPipe,
1414
IgxGridGroupingPipe,
1515
IgxGridSortingPipe,
16-
IgxGridFilteringPipe,
17-
IgxGridRowPinningPipe
16+
IgxGridFilteringPipe
1817
} from './grid.pipes';
1918
import { IgxGridGroupByRowComponent } from './groupby-row.component';
2019
import { IgxGridRowComponent } from './grid-row.component';
@@ -42,7 +41,6 @@ import { IgxGridExpandableCellComponent } from './expandable-cell.component';
4241
IgxGridPagingPipe,
4342
IgxGridSortingPipe,
4443
IgxGridFilteringPipe,
45-
IgxGridRowPinningPipe,
4644
IgxGridSummaryPipe,
4745
IgxGridDetailsPipe,
4846
IgxGridExpandableCellComponent
@@ -63,7 +61,6 @@ import { IgxGridExpandableCellComponent } from './expandable-cell.component';
6361
IgxGridPagingPipe,
6462
IgxGridSortingPipe,
6563
IgxGridFilteringPipe,
66-
IgxGridRowPinningPipe,
6764
IgxGridSummaryPipe,
6865
IgxGridDetailsPipe,
6966
IgxGridCommonModule

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,3 @@ export class IgxGridFilteringPipe implements PipeTransform {
152152
}
153153
}
154154

155-
/**
156-
* @hidden
157-
*/
158-
@Pipe({
159-
name: 'gridRowPinning',
160-
pure: true
161-
})
162-
export class IgxGridRowPinningPipe implements PipeTransform {
163-
164-
constructor(private gridAPI: GridBaseAPIService<IgxGridBaseDirective & GridType>) {}
165-
166-
public transform(collection: any[] , id: string, isPinned = false, pipeTrigger: number) {
167-
const grid = this.gridAPI.grid;
168-
169-
if (!grid.hasPinnedRecords) {
170-
return isPinned ? [] : collection;
171-
}
172-
173-
if (grid.hasPinnedRecords && isPinned) {
174-
const result = collection.filter(rec => grid.isRecordPinned(rec));
175-
result.sort((rec1, rec2) => grid.pinRecordIndex(rec1) - grid.pinRecordIndex(rec2));
176-
return result;
177-
}
178-
179-
grid.unpinnedRecords = collection;
180-
return collection.map((rec) => {
181-
return grid.isRecordPinned(rec) ? { recordRef: rec, ghostRecord: true} : rec;
182-
});
183-
}
184-
}

projects/igniteui-angular/src/lib/grids/grid/grid.search.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ describe('IgxGrid - search API #grid - ', () => {
696696
setupGridScrollDetection(fix, grid);
697697
fix.detectChanges();
698698

699-
grid.data[29] = { ID: 30, Name: 'Eduardo Ramirez', JobTitle: 'Manager', HireDate: '1887-11-28T11:23:17.714Z' };
699+
grid.data[29].HireDate = '1887-11-28T11:23:17.714Z';
700700
grid.width = '500px';
701701
grid.height = '600px';
702702
fixNativeElement = fix.debugElement.nativeElement;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<ng-template #defaultPinnedIndicator>
2+
<igx-chip *ngIf="displayPinnedChip" class="igx-grid__td--pinned-chip" [disabled]="true" [displayDensity]="'compact'">{{ grid.resourceStrings.igx_grid_pinned_row_indicator }}</igx-chip>
3+
</ng-template>
14
<ng-template #defaultCell>
25
<div igxTextHighlight style="pointer-events: none" [cssClass]="highlightClass" [activeCssClass]="activeHighlightClass" [groupName]="gridID"
36
[value]="formatter ? formatter(value) : column.dataType === 'number' ? (value | igxdecimal: grid.locale) : column.dataType === 'date' ? (value | igxdate: grid.locale) : value"
@@ -36,6 +39,8 @@
3639
(click)="toggle($event)" (focus)="onIndicatorFocus()" tabindex="-1">
3740
<ng-container *ngTemplateOutlet="iconTemplate; context: { $implicit: this }">
3841
</ng-container>
42+
<ng-container *ngTemplateOutlet="pinnedIndicatorTemplate; context: context">
43+
</ng-container>
3944
</div>
4045
<div *ngIf="isLoading"
4146
(dblclick)="onLoadingDblClick($event)"

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Component, ChangeDetectorRef, ElementRef, ViewChild, Inject,
2-
ChangeDetectionStrategy, NgZone, OnInit, Input, TemplateRef } from '@angular/core';
3-
import { IgxGridCellComponent } from '../cell.component';
1+
import { Component, ChangeDetectorRef, ElementRef, Inject,
2+
ChangeDetectionStrategy, NgZone, Input } from '@angular/core';
43
import { IgxTreeGridAPIService } from './tree-grid-api.service';
54
import { GridBaseAPIService } from '../api.service';
6-
import { getNodeSizeViaRange, PlatformUtil } from '../../core/utils';
5+
import { PlatformUtil } from '../../core/utils';
76
import { DOCUMENT } from '@angular/common';
87
import { IgxGridBaseDirective } from '../grid';
98
import { IgxGridSelectionService, IgxGridCRUDService } from '../selection/selection.service';
@@ -21,15 +20,15 @@ export class IgxTreeGridCellComponent extends IgxGridExpandableCellComponent {
2120
private treeGridAPI: IgxTreeGridAPIService;
2221

2322
constructor(
24-
selectionService: IgxGridSelectionService,
25-
crudService: IgxGridCRUDService,
26-
gridAPI: GridBaseAPIService<IgxGridBaseDirective & GridType>,
27-
cdr: ChangeDetectorRef,
28-
element: ElementRef,
29-
protected zone: NgZone,
30-
touchManager: HammerGesturesManager,
31-
@Inject(DOCUMENT) public document,
32-
protected platformUtil: PlatformUtil) {
23+
selectionService: IgxGridSelectionService,
24+
crudService: IgxGridCRUDService,
25+
gridAPI: GridBaseAPIService<IgxGridBaseDirective & GridType>,
26+
cdr: ChangeDetectorRef,
27+
element: ElementRef,
28+
protected zone: NgZone,
29+
touchManager: HammerGesturesManager,
30+
@Inject(DOCUMENT) public document,
31+
protected platformUtil: PlatformUtil) {
3332
super(selectionService, crudService, gridAPI, cdr, element, zone, touchManager, document, platformUtil);
3433
this.treeGridAPI = <IgxTreeGridAPIService>gridAPI;
3534
}
@@ -46,7 +45,6 @@ export class IgxTreeGridCellComponent extends IgxGridExpandableCellComponent {
4645
@Input()
4746
showIndicator = false;
4847

49-
5048
/**
5149
* @hidden
5250
*/

0 commit comments

Comments
 (0)