Skip to content

Commit 8c9a572

Browse files
committed
feat(igxGrid): Update navigation to include ghost rows. #6640
1 parent 01e2ceb commit 8c9a572

File tree

6 files changed

+53
-24
lines changed

6 files changed

+53
-24
lines changed

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

+46-14
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
24412441
*/
24422442
public columnWidthSetByUser = false;
24432443

2444+
/**
2445+
* @hidden @internal
2446+
*/
2447+
public pinnedRecords: any[];
2448+
24442449
/**
24452450
* @hidden @internal
24462451
*/
@@ -2657,10 +2662,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
26572662

26582663
/**
26592664
* @hidden
2665+
* Returns the row index of a row that takes into account the full view data like pinning.
26602666
*/
2661-
public getRowIndex(rowIndex, pinned) {
2667+
public getDataViewIndex(rowIndex, pinned) {
26622668
if (pinned && !this.isRowPinningToTop) {
2663-
rowIndex = rowIndex + this.dataView.length;
2669+
rowIndex = rowIndex + this.unpinnedRecords.length;
26642670
} else if (!pinned && this.isRowPinningToTop) {
26652671
rowIndex = rowIndex + this.pinnedRecordsCount;
26662672
}
@@ -2719,6 +2725,15 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
27192725
return this._pinnedRecordIDs.indexOf(id) !== -1;
27202726
}
27212727

2728+
/**
2729+
* @hidden
2730+
* @internal
2731+
*/
2732+
public isRecordPinnedByIndex(rowIndex: number) {
2733+
return this.hasPinnedRecords && (this.isRowPinningToTop && rowIndex < this.pinnedRecordsCount) ||
2734+
(!this.isRowPinningToTop && rowIndex >= this.unpinnedRecords.length);
2735+
}
2736+
27222737
/**
27232738
* @hidden
27242739
* @internal
@@ -5154,25 +5169,38 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
51545169
}
51555170

51565171
/**
5157-
* Returns the currently transformed paged/filtered/sorted/grouped data, displayed in the grid.
5172+
* Returns the currently transformed paged/filtered/sorted/grouped pinned row data, displayed in the grid.
51585173
* @example
51595174
* ```typescript
5160-
* const dataView = this.grid.dataView;
5175+
* const pinnedDataView = this.grid.pinnedDataView;
51615176
* ```
51625177
*/
5163-
get dataView(): any[] {
5164-
return this.unpinnedRecords ? this.unpinnedRecords : this.verticalScrollContainer.igxForOf;
5178+
get pinnedDataView(): any[] {
5179+
return this.pinnedRecords ? this.pinnedRecords : [];
51655180
}
51665181

51675182
/**
5168-
* Returns the currently transformed paged/filtered/sorted/grouped pinned data, displayed in the grid.
5183+
* Returns currently transformed paged/filtered/sorted/grouped unpinned row data, displayed in the grid.
51695184
* @example
51705185
* ```typescript
51715186
* const pinnedDataView = this.grid.pinnedDataView;
51725187
* ```
51735188
*/
5174-
get pinnedDataView(): any[] {
5175-
return this.pinnedRows.map(row => row.rowData);
5189+
get unpinnedDataView(): any[] {
5190+
return this.unpinnedRecords ? this.unpinnedRecords : this.verticalScrollContainer.igxForOf;
5191+
}
5192+
5193+
/**
5194+
* Returns the currently transformed paged/filtered/sorted/grouped row data, displayed in the grid.
5195+
* @example
5196+
* ```typescript
5197+
* const dataView = this.grid.dataView;
5198+
* ```
5199+
*/
5200+
get dataView(): any[] {
5201+
return this.isRowPinningToTop ?
5202+
[...this.pinnedDataView, ...this.unpinnedDataView] :
5203+
[...this.unpinnedDataView, ...this.pinnedDataView];
51765204
}
51775205

51785206
/**
@@ -5415,7 +5443,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
54155443
* If `headers` is enabled, it will use the column header (if any) instead of the column field.
54165444
*/
54175445
public getSelectedData(formatters = false, headers = false) {
5418-
const source = this.isRowPinningToTop ? [...this.pinnedDataView, ...this.dataView] : [...this.dataView, ...this.pinnedDataView];
5446+
const source = this.dataView;
54195447
return this.extractDataFromSelection(source, formatters, headers);
54205448
}
54215449

@@ -5619,10 +5647,14 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
56195647
if (this.dataView.slice(rowIndex, rowIndex + 1).find(rec => rec.expression || rec.childGridsData)) {
56205648
visibleColIndex = -1;
56215649
}
5622-
const shouldScrollVertically = this.navigation.shouldPerformVerticalScroll(rowIndex, visibleColIndex);
5650+
// If the target row is pinned no need to scroll as well.
5651+
const shouldScrollVertically =
5652+
!this.isRecordPinnedByIndex(rowIndex) && this.navigation.shouldPerformVerticalScroll(rowIndex, visibleColIndex);
56235653
const shouldScrollHorizontally = this.navigation.shouldPerformHorizontalScroll(visibleColIndex, rowIndex);
56245654
if (shouldScrollVertically) {
5625-
this.navigation.performVerticalScrollToCell(rowIndex, visibleColIndex,
5655+
// Only for top pinning we need to subtract pinned count because virtualization indexing doesn't count pinned rows.
5656+
const scrollRowIndex = this.isRowPinningToTop ? rowIndex - this.pinnedRecordsCount : rowIndex;
5657+
this.navigation.performVerticalScrollToCell(scrollRowIndex, visibleColIndex,
56265658
() => { this.navigateTo(rowIndex, visibleColIndex, cb); });
56275659
} else if (shouldScrollHorizontally) {
56285660
this.navigation.performHorizontalScrollToCell(visibleColIndex, () => { this.navigateTo(rowIndex, visibleColIndex, cb); });
@@ -5905,11 +5937,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
59055937
if (delayScrolling) {
59065938
this.verticalScrollContainer.onDataChanged.pipe(first()).subscribe(() => {
59075939
this.scrollDirective(this.verticalScrollContainer,
5908-
typeof (row) === 'number' ? row : this.dataView.indexOf(row));
5940+
typeof (row) === 'number' ? row : this.unpinnedDataView.indexOf(row));
59095941
});
59105942
} else {
59115943
this.scrollDirective(this.verticalScrollContainer,
5912-
typeof (row) === 'number' ? row : this.dataView.indexOf(row));
5944+
typeof (row) === 'number' ? row : this.unpinnedDataView.indexOf(row));
59135945
}
59145946

59155947
this.scrollToHorizontally(column);

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,6 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
769769
* @hidden @internal
770770
*/
771771
public getContext(rowData: any, rowIndex: number, pinned?: boolean): any {
772-
if (pinned && !this.isRowPinningToTop) {
773-
rowIndex = rowIndex + this.dataView.length;
774-
}
775-
rowIndex = !pinned && this.isRowPinningToTop ? rowIndex + this._pinnedRecordIDs.length : rowIndex;
776772
if (this.isDetailRecord(rowData)) {
777773
const cachedData = this.childDetailTemplates.get(rowData.detailsData);
778774
const rowID = this.primaryKey ? rowData.detailsData[this.primaryKey] : this.data.indexOf(rowData.detailsData);
@@ -797,7 +793,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
797793
}
798794
return {
799795
$implicit: this.isGhostRecord(rowData) ? rowData.recordRef : rowData,
800-
index: rowIndex,
796+
index: this.getDataViewIndex(rowIndex, pinned),
801797
templateID: this.isGroupByRecord(rowData) ? 'groupRow' : this.isSummaryRow(rowData) ? 'summaryRow' : 'dataRow',
802798
disabled: this.isGhostRecord(rowData)
803799
};

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

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export class IgxGridRowPinningPipe implements PipeTransform {
173173
if (grid.hasPinnedRecords && isPinned) {
174174
const result = collection.filter(rec => grid.isRecordPinned(rec));
175175
result.sort((rec1, rec2) => grid.pinRecordIndex(rec1) - grid.pinRecordIndex(rec2));
176+
grid.pinnedRecords = result;
176177
return result;
177178
}
178179

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ describe('Row Pinning #grid', () => {
416416
expect(grid.pinnedRows.length).toBe(1);
417417
let pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
418418
expect(pinRowContainer.length).toBe(1);
419-
expect(grid.dataView.length).toBe(5);
419+
expect(grid.dataView.length).toBe(6);
420420
expect(paginator.componentInstance.totalPages).toEqual(6);
421421

422422
grid.getRowByIndex(3).pin();
@@ -425,7 +425,7 @@ describe('Row Pinning #grid', () => {
425425
expect(grid.pinnedRows.length).toBe(2);
426426
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
427427
expect(pinRowContainer.length).toBe(1);
428-
expect(grid.dataView.length).toBe(5);
428+
expect(grid.dataView.length).toBe(7);
429429
expect(paginator.componentInstance.totalPages).toEqual(6);
430430

431431
// unpin
@@ -439,7 +439,7 @@ describe('Row Pinning #grid', () => {
439439
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
440440
expect(pinRowContainer.length).toBe(0);
441441

442-
expect(grid.dataView.length).toBe(5);
442+
expect(grid.dataView.length).toBe(6);
443443
expect(paginator.componentInstance.totalPages).toEqual(6);
444444
});
445445

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
'igx-grid__tr-container': true,
141141
'igx-grid__tr--highlighted':isRowHighlighted(rowData)
142142
}">
143-
<igx-child-grid-row *ngFor="let layout of childLayoutList" [parentGridID]="id" [index]="getRowIndex(rowIndex, false)"
143+
<igx-child-grid-row *ngFor="let layout of childLayoutList" [parentGridID]="id" [index]="rowIndex"
144144
[rowData]="rowData" [layout]='layout' #row>
145145
</igx-child-grid-row>
146146
</div>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
547547
return {
548548
$implicit: this.isGhostRecord(rowData) ? rowData.recordRef : rowData,
549549
templateID: 'dataRow',
550-
index: this.getRowIndex(rowIndex, pinned),
550+
index: this.getDataViewIndex(rowIndex, pinned),
551551
disabled: this.isGhostRecord(rowData)
552552
};
553553
}

0 commit comments

Comments
 (0)