Skip to content

Commit 89e9462

Browse files
committed
feat(pivot): keyboard nav for pivot rows and values
1 parent f4e9845 commit 89e9462

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface IActiveNode {
2828
level?: number;
2929
mchCache?: ColumnGroupsCache;
3030
layout?: IMultiRowLayoutNode;
31+
isRowDimensionHeader?: boolean;
3132
}
3233

3334
/** @hidden */
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
11
import { IgxGridNavigationService } from '../grid-navigation.service';
22
import { Injectable } from '@angular/core';
33
import { IgxPivotGridComponent } from './pivot-grid.component';
4+
import { HEADER_KEYS } from '../../core/utils';
45

56
@Injectable()
67
export class IgxPivotGridNavigationService extends IgxGridNavigationService {
78
public grid: IgxPivotGridComponent;
89

9-
public dispatchEvent(event: KeyboardEvent) {
10-
// TODO
10+
public get lastRowDimensionsIndex() {
11+
return this.grid.rowDimensions.length - 1;
12+
}
13+
14+
public focusValueCells() {
15+
this.activeNode.isRowDimensionHeader = false;
16+
}
17+
18+
public headerNavigation(event: KeyboardEvent) {
19+
const key = event.key.toLowerCase();
20+
const ctrl = event.ctrlKey;
21+
if (!HEADER_KEYS.has(key)) {
22+
return;
23+
}
24+
event.preventDefault();
25+
26+
const newActiveNode = {
27+
row: this.activeNode.row, column: this.activeNode.column, level: null,
28+
mchCache: null,
29+
layout: null,
30+
isRowDimensionHeader: this.activeNode.isRowDimensionHeader
31+
}
32+
33+
if ((key.includes('left') || key === 'home') && this.activeNode.column > 0) {
34+
newActiveNode.column = ctrl || key === 'home' ? 0 : this.activeNode.column - 1;
35+
}
36+
if ((key.includes('right') || key === 'end') && this.activeNode.column < this.lastRowDimensionsIndex) {
37+
newActiveNode.column = ctrl || key === 'end' ? this.lastRowDimensionsIndex : this.activeNode.column + 1;
38+
}
39+
if ((key.includes('up')) && this.activeNode.row > 0) {
40+
newActiveNode.row = ctrl ? 0 : this.activeNode.row - 1;
41+
}
42+
if ((key.includes('down')) && this.activeNode.row < this.findLastDataRowIndex()) {
43+
newActiveNode.row = ctrl ? this.findLastDataRowIndex() : this.activeNode.row + 1;
44+
}
45+
this.setActiveNode(newActiveNode);
46+
this.grid.navigateTo(newActiveNode.row);
1147
}
1248
}

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-row-dimension-header-group.component.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class IgxPivotRowDimensionHeaderGroupComponent extends IgxGridHeaderGroup
4545
*/
4646
public get visibleIndex(): number {
4747
const field = this.column.field;
48-
const rows = this.grid.pivotConfiguration.rows;
48+
const rows = this.grid.rowDimensions;
4949
const rootDimension = this.findRootDimension(field);
5050
return rows.indexOf(rootDimension);
5151
}
@@ -54,31 +54,34 @@ export class IgxPivotRowDimensionHeaderGroupComponent extends IgxGridHeaderGroup
5454
public get active() {
5555
const node = this.grid.navigation.activeNode;
5656
return node && !this.column.columnGroup ?
57-
node.isRowHeader && node.row === this.intRow.index && node.column === this.visibleIndex : false;
57+
node.isRowDimensionHeader &&
58+
node.row === this.intRow.index &&
59+
node.column === this.visibleIndex :
60+
false;
5861
}
5962

6063
public get activeGroup() {
6164
const node = this.grid.navigation.activeNode;
62-
return node ? node.isRowHeader && node.row === this.intRow.index && node.column === this.visibleIndex : false;
65+
return node ? node.isRowDimensionHeader && node.row === this.intRow.index && node.column === this.visibleIndex : false;
6366
}
6467

6568
protected get activeNode() {
6669
return {
6770
row: this.intRow.index, column: this.visibleIndex, level: null,
6871
mchCache: null,
6972
layout: null,
70-
isRowHeader: true
73+
isRowDimensionHeader: true
7174
};
7275
}
7376

7477
private findRootDimension(field: string): IPivotDimension {
75-
const rows = this.grid.pivotConfiguration.rows;
78+
const rows = this.grid.rowDimensions;
7679
let tempRow;
7780
let result = null;
7881
rows.forEach(row => {
7982
tempRow = row;
8083
do {
81-
if (row.memberName === field) {
84+
if (tempRow.memberName === field) {
8285
result = row;
8386
}
8487
tempRow = tempRow.childLevel;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
[column]="col"
3333
[formatter]="col.formatter"
3434
[intRow]="this"
35-
[active]="isPivotCellActive(col)"
35+
[active]="isCellActive(col.visibleIndex)"
3636
[style.min-height.px]="cellHeight"
3737
[data]="data"
3838
[style.min-width]="col.width"
@@ -44,7 +44,8 @@
4444
[cellTemplate]="col.bodyTemplate"
4545
[lastSearchInfo]="grid.lastSearchInfo"
4646
[cellSelectionMode]="grid.cellSelection"
47-
[displayPinnedChip]="shouldDisplayPinnedChip(col.visibleIndex)">
47+
[displayPinnedChip]="shouldDisplayPinnedChip(col.visibleIndex)"
48+
(pointerdown)="grid.navigation.focusValueCells($event)">
4849
</igx-grid-cell>
4950
</ng-template>
5051

@@ -78,7 +79,7 @@
7879
[column]="col"
7980
[formatter]="col.formatter"
8081
[intRow]="this"
81-
[active]="isPivotCellActive(col)"
82+
[active]="isCellActive(col.visibleIndex)"
8283
[firstPinned]="col.isFirstPinned"
8384
[lastPinned]="col.isLastPinned"
8485
[style.min-height.px]="cellHeight"
@@ -93,7 +94,8 @@
9394
[cellTemplate]="col.bodyTemplate"
9495
[lastSearchInfo]="grid.lastSearchInfo"
9596
[cellSelectionMode]="grid.cellSelection"
96-
[displayPinnedChip]="shouldDisplayPinnedChip(col.visibleIndex)">
97+
[displayPinnedChip]="shouldDisplayPinnedChip(col.visibleIndex)"
98+
(pointerdown)="grid.navigation.focusValueCells($event)">
9799
</igx-grid-cell>
98100
</ng-template>
99101

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
104104
return this.grid.pivotConfiguration.values.find(v => v.member === measureName)?.styles;
105105
}
106106

107-
public isPivotCellActive(col: IgxColumnComponent) {
107+
public isCellActive(visibleColumnIndex) {
108108
const node = this.grid.navigation.activeNode;
109-
return node ? !node.isRowHeader && super.isCellActive(col.visibleIndex) : false;
109+
console.log(node && Object.keys(node).length === 0 && !node.isRowDimensionHeader && super.isCellActive(visibleColumnIndex));
110+
return node && Object.keys(node).length !== 0 ?
111+
!node.isRowDimensionHeader &&
112+
super.isCellActive(visibleColumnIndex) :
113+
false;
110114
}
111115

112116
protected extractFromDimensions(rowDimConfig: IPivotDimension[], level: number) {

0 commit comments

Comments
 (0)