Skip to content

Commit 6fce6d3

Browse files
authored
Merge pull request #11441 from IgniteUI/mkirova/fix-11416-master
fix(igxGrid): Add handling for remote virtualization navigation.
2 parents 7cef566 + 6a7fcfb commit 6fce6d3

File tree

7 files changed

+47
-25
lines changed

7 files changed

+47
-25
lines changed

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

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,7 +4237,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
42374237
* @hidden
42384238
* @internal
42394239
*/
4240-
protected _getResolvedDataIndex(index: number): number {
4240+
protected _getDataViewIndex(index: number): number {
42414241
let newIndex = index;
42424242
if ((index < 0 || index >= this.dataView.length) && this.pagingMode === 1 && this.paginator.page !== 0) {
42434243
newIndex = index - this.paginator.perPage * this.paginator.page;
@@ -4247,6 +4247,18 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
42474247
return newIndex;
42484248
}
42494249

4250+
/**
4251+
* @hidden
4252+
* @internal
4253+
*/
4254+
protected getDataIndex(dataViewIndex: number): number {
4255+
let newIndex = dataViewIndex;
4256+
if (this.gridAPI.grid.verticalScrollContainer.isRemote) {
4257+
newIndex = dataViewIndex + this.gridAPI.grid.virtualizationState.startIndex;
4258+
}
4259+
return newIndex;
4260+
}
4261+
42504262
/**
42514263
* Places a column before or after the specified target column.
42524264
*
@@ -5697,21 +5709,22 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
56975709
public getNextCell(currRowIndex: number, curVisibleColIndex: number,
56985710
callback: (IgxColumnComponent) => boolean = null): ICellPosition {
56995711
const columns = this.columnList.filter(col => !col.columnGroup && col.visibleIndex >= 0);
5700-
5701-
if (!this.isValidPosition(currRowIndex, curVisibleColIndex)) {
5712+
const dataViewIndex = this._getDataViewIndex(currRowIndex);
5713+
if (!this.isValidPosition(dataViewIndex, curVisibleColIndex)) {
57025714
return { rowIndex: currRowIndex, visibleColumnIndex: curVisibleColIndex };
57035715
}
57045716
const colIndexes = callback ? columns.filter((col) => callback(col)).map(editCol => editCol.visibleIndex).sort((a, b) => a - b) :
57055717
columns.map(editCol => editCol.visibleIndex).sort((a, b) => a - b);
57065718
const nextCellIndex = colIndexes.find(index => index > curVisibleColIndex);
5707-
if (this.dataView.slice(currRowIndex, currRowIndex + 1)
5719+
if (this.dataView.slice(dataViewIndex, dataViewIndex + 1)
57085720
.find(rec => !rec.expression && !rec.summaries && !rec.childGridsData && !rec.detailsData) && nextCellIndex !== undefined) {
57095721
return { rowIndex: currRowIndex, visibleColumnIndex: nextCellIndex };
57105722
} else {
5711-
if (colIndexes.length === 0 || this.getNextDataRowIndex(currRowIndex) === currRowIndex) {
5723+
const nextIndex = this.getNextDataRowIndex(currRowIndex)
5724+
if (colIndexes.length === 0 || nextIndex === currRowIndex) {
57125725
return { rowIndex: currRowIndex, visibleColumnIndex: curVisibleColIndex };
57135726
} else {
5714-
return { rowIndex: this.getNextDataRowIndex(currRowIndex), visibleColumnIndex: colIndexes[0] };
5727+
return { rowIndex: nextIndex, visibleColumnIndex: colIndexes[0] };
57155728
}
57165729
}
57175730
}
@@ -5731,21 +5744,22 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
57315744
public getPreviousCell(currRowIndex: number, curVisibleColIndex: number,
57325745
callback: (IgxColumnComponent) => boolean = null): ICellPosition {
57335746
const columns = this.columnList.filter(col => !col.columnGroup && col.visibleIndex >= 0);
5734-
5735-
if (!this.isValidPosition(currRowIndex, curVisibleColIndex)) {
5747+
const dataViewIndex = this._getDataViewIndex(currRowIndex);
5748+
if (!this.isValidPosition(dataViewIndex, curVisibleColIndex)) {
57365749
return { rowIndex: currRowIndex, visibleColumnIndex: curVisibleColIndex };
57375750
}
57385751
const colIndexes = callback ? columns.filter((col) => callback(col)).map(editCol => editCol.visibleIndex).sort((a, b) => b - a) :
57395752
columns.map(editCol => editCol.visibleIndex).sort((a, b) => b - a);
57405753
const prevCellIndex = colIndexes.find(index => index < curVisibleColIndex);
5741-
if (this.dataView.slice(currRowIndex, currRowIndex + 1)
5754+
if (this.dataView.slice(dataViewIndex, dataViewIndex + 1)
57425755
.find(rec => !rec.expression && !rec.summaries && !rec.childGridsData && !rec.detailsData) && prevCellIndex !== undefined) {
57435756
return { rowIndex: currRowIndex, visibleColumnIndex: prevCellIndex };
57445757
} else {
5745-
if (colIndexes.length === 0 || this.getNextDataRowIndex(currRowIndex, true) === currRowIndex) {
5758+
const prevIndex = this.getNextDataRowIndex(currRowIndex, true);
5759+
if (colIndexes.length === 0 || prevIndex === currRowIndex) {
57465760
return { rowIndex: currRowIndex, visibleColumnIndex: curVisibleColIndex };
57475761
} else {
5748-
return { rowIndex: this.getNextDataRowIndex(currRowIndex, true), visibleColumnIndex: colIndexes[0] };
5762+
return { rowIndex: prevIndex, visibleColumnIndex: colIndexes[0] };
57495763
}
57505764
}
57515765
}
@@ -7148,8 +7162,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
71487162
cb(cbArgs);
71497163
});
71507164
}
7151-
7152-
if (this.dataView[rowIndex].detailsData) {
7165+
const dataViewIndex = this._getDataViewIndex(rowIndex);
7166+
if (this.dataView[dataViewIndex].detailsData) {
71537167
this.navigation.setActiveNode({ row: rowIndex });
71547168
this.cdr.detectChanges();
71557169
}
@@ -7185,14 +7199,16 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
71857199
}
71867200

71877201
private getNextDataRowIndex(currentRowIndex, previous = false): number {
7188-
if (currentRowIndex < 0 || (currentRowIndex === 0 && previous) || (currentRowIndex >= this.dataView.length - 1 && !previous)) {
7202+
const resolvedIndex = this._getDataViewIndex(currentRowIndex);
7203+
if (currentRowIndex < 0 || (currentRowIndex === 0 && previous) || (resolvedIndex >= this.dataView.length - 1 && !previous)) {
71897204
return currentRowIndex;
71907205
}
71917206
// find next/prev record that is editable.
71927207
const nextRowIndex = previous ? this.findPrevEditableDataRowIndex(currentRowIndex) :
71937208
this.dataView.findIndex((rec, index) =>
7194-
index > currentRowIndex && this.isEditableDataRecordAtIndex(index));
7195-
return nextRowIndex !== -1 ? nextRowIndex : currentRowIndex;
7209+
index > resolvedIndex && this.isEditableDataRecordAtIndex(index));
7210+
const nextDataIndex = this.getDataIndex(nextRowIndex);
7211+
return nextDataIndex !== -1 ? nextDataIndex : currentRowIndex;
71967212
}
71977213

71987214
/**
@@ -7202,8 +7218,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
72027218
*/
72037219
private findPrevEditableDataRowIndex(currentIndex): number {
72047220
let i = this.dataView.length;
7221+
const resolvedIndex = this._getDataViewIndex(currentIndex);
72057222
while (i--) {
7206-
if (i < currentIndex && this.isEditableDataRecordAtIndex(i)) {
7223+
if (i < resolvedIndex && this.isEditableDataRecordAtIndex(i)) {
72077224
return i;
72087225
}
72097226
}

projects/igniteui-angular/src/lib/grids/grid-navigation.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ export class IgxGridNavigationService {
259259
if (rowIndex < 0 || rowIndex > this.grid.dataView.length - 1) {
260260
curRow = this.grid.dataView[rowIndex - this.grid.virtualizationState.startIndex];
261261
if (!curRow) {
262-
return false;
262+
// if data is remote, record might not be in the view yet.
263+
return this.grid.verticalScrollContainer.isRemote && rowIndex >= 0 && rowIndex <= (this.grid as any).totalItemCount - 1;
263264
}
264265
} else {
265266
curRow = this.grid.dataView[rowIndex];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
11621162
let row: RowType;
11631163
let rec: any;
11641164

1165-
const dataIndex = this._getResolvedDataIndex(index);
1165+
const dataIndex = this._getDataViewIndex(index);
11661166
rec = data ?? this.dataView[dataIndex];
11671167

11681168
if (rec && this.isGroupByRecord(rec)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
833833
*/
834834
public isChildGridRecord(record: any): boolean {
835835
// Can be null when there is defined layout but no child data was found
836-
return record.childGridsData !== undefined;
836+
return record?.childGridsData !== undefined;
837837
}
838838

839839
/**
@@ -1042,7 +1042,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
10421042
*/
10431043
public createRow(index: number, data?: any): RowType {
10441044
let row: RowType;
1045-
const dataIndex = this._getResolvedDataIndex(index);
1045+
const dataIndex = this._getDataViewIndex(index);
10461046
const rec: any = data ?? this.dataView[dataIndex];
10471047

10481048
if (!row && rec && !rec.childGridsData) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
866866
*/
867867
public createRow(index: number, data?: any): RowType {
868868
let row: RowType;
869-
const dataIndex = this._getResolvedDataIndex(index);
869+
const dataIndex = this._getDataViewIndex(index);
870870
const rec: any = data ?? this.dataView[dataIndex];
871871

872872
if (this.isSummaryRow(rec)) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="dark-grid">
2-
<igx-grid #grid1 [data]="remoteData | async" [height]="'500px'" [width]="'100%'" [autoGenerate]='true' (dataPreLoad)="handlePreLoad()" [clipboardOptions]="clipboardOptions"
3-
(sortingDone)="processData(true)">
2+
<igx-grid batchEditing ='true' #grid1 [data]="remoteData | async" [height]="'500px'" [width]="'100%'" [autoGenerate]='true' (dataPreLoad)="handlePreLoad()" [clipboardOptions]="clipboardOptions"
3+
(sortingDone)="processData(true)" (columnInit)='onColumnInit($event)'>
44
</igx-grid>
55
</div>

src/app/grid-remote-virtualization-with-scroll/grid-remote-virtualization-scroll.sample.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, ViewChild, ChangeDetectorRef, OnInit, AfterViewInit } from '@angular/core';
2-
import { IgxGridComponent } from 'igniteui-angular';
2+
import { IgxColumnComponent, IgxGridComponent } from 'igniteui-angular';
33
import { debounceTime } from 'rxjs/operators';
44
import { RemoteVirtService } from '../shared/remoteProductsData.service';
55

@@ -30,6 +30,10 @@ export class GridVirtualizationScrollSampleComponent implements OnInit, AfterVie
3030
this.remoteData = this.remoteService.data;
3131
}
3232

33+
public onColumnInit(col: IgxColumnComponent) {
34+
col.editable = true;
35+
}
36+
3337
public ngAfterViewInit() {
3438
this.grid.isLoading = true;
3539

0 commit comments

Comments
 (0)