Skip to content

Commit 42370c7

Browse files
committed
fix(igxGrid): Keyboard navigation with MCH
Closes #488
1 parent f702a5d commit 42370c7

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

Diff for: projects/igniteui-angular/src/lib/grid/cell.component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class IgxGridCellComponent implements OnInit, OnDestroy, AfterViewInit {
8787
}
8888

8989
get unpinnedColumnIndex(): number {
90-
return this.grid.unpinnedColumns.indexOf(this.column);
90+
return this.grid.unpinnedColumns.filter(c => !c.columnGroup).indexOf(this.column);
9191
}
9292

9393
public get cellID() {
@@ -422,7 +422,7 @@ export class IgxGridCellComponent implements OnInit, OnDestroy, AfterViewInit {
422422
if (!this.column.pinned) {
423423
this.row.virtDirRow.scrollPrev();
424424
} else {
425-
this.row.virtDirRow.scrollTo(this.grid.unpinnedColumns.length - 1);
425+
this.row.virtDirRow.scrollTo(this.grid.unpinnedColumns.filter(c => !c.columnGroup).length - 1);
426426
}
427427
}
428428

@@ -468,7 +468,7 @@ export class IgxGridCellComponent implements OnInit, OnDestroy, AfterViewInit {
468468
}
469469

470470
event.preventDefault();
471-
const visibleColumns = this.grid.visibleColumns;
471+
const visibleColumns = this.grid.visibleColumns.filter(c => !c.columnGroup);
472472
const rowIndex = this.rowIndex;
473473
const columnIndex = this.visibleColumnIndex + 1;
474474

Diff for: projects/igniteui-angular/src/lib/grid/column.component.ts

+27-14
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class IgxColumnComponent implements AfterContentInit {
151151
public set pinned(value: boolean) {
152152
if (this._pinned !== value) {
153153
if (this.grid && this.width && !isNaN(parseInt(this.width, 10))) {
154-
value ? this._pinColumn() : this._unpinColumn();
154+
value ? this.pin() : this.unpin();
155155
return;
156156
}
157157
/* No grid/width available at initialization. `initPinning` in the grid
@@ -235,17 +235,20 @@ export class IgxColumnComponent implements AfterContentInit {
235235

236236
get visibleIndex(): number {
237237
const grid = this.gridAPI.get(this.gridID);
238+
const unpinnedColumns = this.grid.unpinnedColumns.filter(c => !c.columnGroup);
239+
const pinnedColumns = this.grid.pinnedColumns.filter(c => !c.columnGroup);
240+
let col = this;
238241
let vIndex = -1;
239242

240243
if (this.columnGroup) {
241-
return vIndex;
244+
col = this.allChildren.filter(c => !c.columnGroup)[0] as any;
242245
}
243246

244247
if (!this.pinned) {
245-
const indexInCollection = grid.unpinnedColumns.indexOf(this);
246-
vIndex = indexInCollection === -1 ? -1 : grid.pinnedColumns.length + indexInCollection;
248+
const indexInCollection = unpinnedColumns.indexOf(col);
249+
vIndex = indexInCollection === -1 ? -1 : pinnedColumns.length + indexInCollection;
247250
} else {
248-
vIndex = grid.pinnedColumns.indexOf(this);
251+
vIndex = pinnedColumns.indexOf(col);
249252
}
250253
return vIndex;
251254
}
@@ -360,24 +363,27 @@ export class IgxColumnComponent implements AfterContentInit {
360363
}
361364
}
362365

363-
public _pinColumn(index?) {
366+
public pin(index?) {
364367
// TODO: Probably should the return type of the old functions
365368
// should be moved as a event parameter.
366369

370+
if (this._pinned) {
371+
return false;
372+
}
373+
367374
if (this.parent && !this.parent.pinned) {
368-
this.topLevelParent.pinned = true;
369-
return;
375+
return this.topLevelParent.pin(index);
370376
}
371377

372378
const grid = (this.grid as any);
373379
const width = parseInt(this.width, 10);
380+
const oldIndex = this.visibleIndex;
374381

375382
if (grid.getUnpinnedWidth(true) - width < grid.unpinnedAreaMinWidth) {
376383
return false;
377384
}
378385

379386
this._pinned = true;
380-
const oldIndex = this.visibleIndex;
381387
this._unpinnedIndex = grid._unpinnedColumns.indexOf(this);
382388
index = index !== undefined ? index : grid._pinnedColumns.length;
383389
const args = { column: this, insertAtIndex: index };
@@ -394,22 +400,28 @@ export class IgxColumnComponent implements AfterContentInit {
394400
if (this.columnGroup) {
395401
this.children.forEach(child => child.pinned = true);
396402
}
397-
grid.reinitPinStates();
403+
// grid.reinitPinStates();
398404

399405
grid.markForCheck();
400406
const newIndex = this.visibleIndex;
401407
this.updateHighlights(oldIndex, newIndex);
408+
return true;
402409
}
403410

404-
public _unpinColumn(index?) {
411+
public unpin(index?) {
412+
413+
if (!this._pinned) {
414+
return false;
415+
}
416+
405417
if (this.parent && this.parent.pinned) {
406-
this.topLevelParent.pinned = false;
407-
return;
418+
return this.topLevelParent.unpin(index);
408419
}
409420

410421
const grid = (this.grid as any);
411422
const oldIndex = this.visibleIndex;
412-
index = index !== undefined ? index : this._unpinnedIndex;
423+
index = (index !== undefined ? index :
424+
this._unpinnedIndex !== undefined ? this._unpinnedIndex : this.index);
413425
this._pinned = false;
414426

415427
grid._unpinnedColumns.splice(index, 0, this);
@@ -425,6 +437,7 @@ export class IgxColumnComponent implements AfterContentInit {
425437
grid.markForCheck();
426438
const newIndex = this.visibleIndex;
427439
this.updateHighlights(oldIndex, newIndex);
440+
return true;
428441
}
429442

430443
get topLevelParent() {

Diff for: projects/igniteui-angular/src/lib/grid/grid.component.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ export class IgxGridComponent implements OnInit, OnDestroy, AfterContentInit, Af
10661066
}
10671067

10681068
if (dropTarget.pinned && !column.pinned) {
1069-
column._pinColumn(dropTarget.index);
1069+
column.pin(dropTarget.index);
10701070
return;
10711071
}
10721072

@@ -1279,16 +1279,14 @@ export class IgxGridComponent implements OnInit, OnDestroy, AfterContentInit, Af
12791279

12801280
// TODO: We have return values here. Move them to event args ??
12811281

1282-
public pinColumn(columnName: string | IgxColumnComponent): boolean {
1282+
public pinColumn(columnName: string | IgxColumnComponent, index?): boolean {
12831283
const col = columnName instanceof IgxColumnComponent ? columnName : this.getColumnByName(columnName);
1284-
col.pinned = true;
1285-
return true;
1284+
return col.pin(index);
12861285
}
12871286

1288-
public unpinColumn(columnName: string | IgxColumnComponent): boolean {
1287+
public unpinColumn(columnName: string | IgxColumnComponent, index?): boolean {
12891288
const col = columnName instanceof IgxColumnComponent ? columnName : this.getColumnByName(columnName);
1290-
col.pinned = false;
1291-
return true;
1289+
return col.unpin(index);
12921290
}
12931291

12941292
public toggleAllGroupRows() {

Diff for: projects/igniteui-angular/src/lib/grid/grid.pinning.spec.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { Component, ViewChild } from '@angular/core';
2-
import { async, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
2+
import { async, discardPeriodicTasks, fakeAsync, TestBed, tick } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { Calendar } from '../calendar/index';
6-
import { KEYCODES } from '../core/utils';
7-
import { DataType } from '../data-operations/data-util';
86
import { SortingDirection } from '../data-operations/sorting-expression.interface';
9-
import { IgxGridCellComponent } from './cell.component';
107
import { IgxColumnComponent } from './column.component';
118
import { IgxGridHeaderComponent } from './grid-header.component';
129
import { IGridCellEventArgs, IgxGridComponent } from './grid.component';
@@ -568,17 +565,13 @@ describe('IgxGrid - Column Pinning ', () => {
568565
const pinnedColumnsLength = grid.pinnedColumns.length;
569566
const unpinnedColumnsLength = grid.unpinnedColumns.length;
570567

571-
let col = grid.getColumnByName('CompanyName');
572-
573-
let result = col.pinned = true;
568+
let result = grid.pinColumn('CompanyName');
574569
fix.detectChanges();
575570

576571
expect(grid.pinnedColumns.length).toEqual(pinnedColumnsLength);
577572
expect(result).toBe(false);
578573

579-
col = grid.getColumnByName('City');
580-
581-
result = col.pinned = false;
574+
result = grid.unpinColumn('City');
582575
fix.detectChanges();
583576

584577
expect(grid.unpinnedColumns.length).toEqual(unpinnedColumnsLength);

0 commit comments

Comments
 (0)