Skip to content

Commit aa51d2c

Browse files
ddinchevanrobakovarkaraivanov
authored
KB navigation in grid with remote virtualization (#7558)
* fix(IgxGrid): allow kb navigation with remote virtualization #7448 * fix(Grid): go to the last row on ctrl+arrowDown in grid with remote virtualization #7448 * fix(*): update selection correctly when navigate in grid remote virt #7448 Co-authored-by: Nadia Robakova <[email protected]> Co-authored-by: Radoslav Karaivanov <[email protected]>
1 parent 7f0794c commit aa51d2c

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,8 +5721,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
57215721
* ```
57225722
*/
57235723
public navigateTo(rowIndex: number, visibleColIndex = -1, cb: Function = null) {
5724-
if (rowIndex < 0 || rowIndex > this.dataView.length - 1
5725-
|| (visibleColIndex !== -1 && this.columnList.map(col => col.visibleIndex).indexOf(visibleColIndex) === -1)) {
5724+
const totalItems = (this as any).totalItemCount ?? this.dataView.length - 1;
5725+
if (rowIndex < 0 || rowIndex > totalItems || (visibleColIndex !== -1
5726+
&& this.columnList.map(col => col.visibleIndex).indexOf(visibleColIndex) === -1)) {
57265727
return;
57275728
}
57285729
if (this.dataView.slice(rowIndex, rowIndex + 1).find(rec => rec.expression || rec.childGridsData)) {
@@ -5820,9 +5821,24 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
58205821

58215822
private executeCallback(rowIndex, visibleColIndex = -1, cb: Function = null) {
58225823
if (!cb) { return; }
5824+
let row = this.summariesRowList.filter(s => s.index !== 0).concat(this.rowList.toArray()).find(r => r.index === rowIndex);
5825+
if (!row) {
5826+
if ((this as any).totalItemCount) {
5827+
this.verticalScrollContainer.onDataChanged.pipe(first()).subscribe(() => {
5828+
this.cdr.detectChanges();
5829+
row = this.summariesRowList.filter(s => s.index !== 0).concat(this.rowList.toArray()).find(r => r.index === rowIndex);
5830+
const cbArgs = this.getNavigationArguments(row, visibleColIndex);
5831+
cb(cbArgs);
5832+
});
5833+
}
5834+
return;
5835+
}
5836+
const args = this.getNavigationArguments(row, visibleColIndex);
5837+
cb(args);
5838+
}
5839+
5840+
private getNavigationArguments(row, visibleColIndex) {
58235841
let targetType, target;
5824-
const row = this.summariesRowList.filter(s => s.index !== 0).concat(this.rowList.toArray()).find(r => r.index === rowIndex);
5825-
if (!row) { return; }
58265842
switch (row.nativeElement.tagName.toLowerCase()) {
58275843
case 'igx-grid-groupby-row':
58285844
targetType = GridKeydownTargetType.groupRow;
@@ -5842,8 +5858,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
58425858
target = visibleColIndex !== -1 ? row.cells.find(c => c.visibleColumnIndex === visibleColIndex) : row.cells.first;
58435859
break;
58445860
}
5845-
const args = { targetType: targetType, target: target };
5846-
cb(args);
5861+
return { targetType: targetType, target: target };
58475862
}
58485863

58495864
private getNextDataRowIndex(currentRowIndex, previous = false): number {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export class IgxGridNavigationService {
359359
}
360360

361361
protected findLastDataRowIndex(): number {
362+
if ((this.grid as any).totalItemCount) { return (this.grid as any).totalItemCount - 1; }
362363
let i = this.grid.dataView.length;
363364
while (i--) {
364365
if (this.isDataRow(i)) {
@@ -376,7 +377,8 @@ export class IgxGridNavigationService {
376377
}
377378

378379
protected isValidPosition(rowIndex: number, colIndex: number): boolean {
379-
if (rowIndex < 0 || colIndex < 0 || this.grid.dataView.length - 1 < rowIndex || this.lastColumnIndex < colIndex) {
380+
const length = (this.grid as any).totalItemCount ?? this.grid.dataView.length;
381+
if (rowIndex < 0 || colIndex < 0 || length - 1 < rowIndex || this.lastColumnIndex < colIndex) {
380382
return false;
381383
}
382384
return this.activeNode.column !== colIndex && !this.isDataRow(rowIndex, true) ? false : true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, ViewChild, ChangeDetectorRef, OnInit, AfterViewInit } from '@angular/core';
22
import { IgxGridComponent } from 'igniteui-angular';
33
import { debounceTime } from 'rxjs/operators';
4-
import { RemoteVirtService } from '../shared/remote.service - Copy';
4+
import { RemoteVirtService } from '../shared/remoteProductsData.service';
55

66
@Component({
77
selector: 'app-grid-remote-virtualization-scroll',

0 commit comments

Comments
 (0)