Skip to content

Commit 52ea88f

Browse files
authored
Merge branch 'master' into rkaraivanov/remove-raf-81x
2 parents e9e6e4b + 0b9be32 commit 52ea88f

File tree

4 files changed

+90
-20
lines changed

4 files changed

+90
-20
lines changed

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4784,28 +4784,26 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
47844784
}
47854785

47864786
extractDataFromSelection(source: any[]): any[] {
4787-
let column: IgxColumnComponent;
4787+
let columnsArray: IgxColumnComponent[];
47884788
let record = {};
47894789
const selectedData = [];
47904790

47914791
const selectionMap = Array.from(this.selectionService.selection)
47924792
.filter((tuple) => tuple[0] < source.length);
47934793

4794-
const visibleColumns = this.visibleColumns
4795-
.filter(col => !col.columnGroup)
4796-
.sort((a, b) => a.visibleIndex - b.visibleIndex);
4797-
47984794

47994795
for (const [row, set] of selectionMap) {
48004796
if (!source[row]) {
48014797
continue;
48024798
}
48034799
const temp = Array.from(set);
48044800
for (const each of temp) {
4805-
column = visibleColumns[each];
4806-
if (column) {
4807-
record[column.field] = source[row][column.field];
4808-
}
4801+
columnsArray = this.getSelectableColumnsAt(each);
4802+
columnsArray.forEach((col) => {
4803+
if (col) {
4804+
record[col.field] = source[row][col.field];
4805+
}
4806+
});
48094807
}
48104808
if (Object.keys(record).length) {
48114809
selectedData.push(record);
@@ -4815,6 +4813,21 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
48154813
return selectedData;
48164814
}
48174815

4816+
protected getSelectableColumnsAt(index) {
4817+
if (this.hasColumnLayouts) {
4818+
const visibleLayoutColumns = this.visibleColumns
4819+
.filter(col => col.columnLayout)
4820+
.sort((a, b) => a.visibleIndex - b.visibleIndex);
4821+
const colLayout = visibleLayoutColumns[index];
4822+
return colLayout ? colLayout.children.toArray() : [];
4823+
} else {
4824+
const visibleColumns = this.visibleColumns
4825+
.filter(col => !col.columnGroup)
4826+
.sort((a, b) => a.visibleIndex - b.visibleIndex);
4827+
return [ visibleColumns[index] ];
4828+
}
4829+
}
4830+
48184831
getSelectedData() {
48194832
const source = this.verticalScrollContainer.igxForOf;
48204833

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class IgxGridNavigationService {
131131
if (this.isColumnLeftEdgeVisible(visibleColumnIndex + 1)) {
132132
element.nextElementSibling.firstElementChild.focus({ preventScroll: true });
133133
} else {
134-
this.grid.nativeElement.focus({ preventScroll: true });
134+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
135135
this.grid.parentVirtDir.onChunkLoad
136136
.pipe(first())
137137
.subscribe(() => {
@@ -205,7 +205,7 @@ export class IgxGridNavigationService {
205205
if (this.grid.pinnedColumns.length || this.displayContainerScrollLeft === 0) {
206206
firstCell.focus({ preventScroll: true });
207207
} else {
208-
this.grid.nativeElement.focus({ preventScroll: true });
208+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
209209
this.grid.parentVirtDir.onChunkLoad
210210
.pipe(first())
211211
.subscribe(() => {
@@ -226,7 +226,7 @@ export class IgxGridNavigationService {
226226
const allCells = rowElement.querySelectorAll(this.getCellSelector(-1, isSummary));
227227
allCells[allCells.length - 1].focus({ preventScroll: true });
228228
} else {
229-
this.grid.nativeElement.focus({ preventScroll: true });
229+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
230230
this.grid.parentVirtDir.onChunkLoad
231231
.pipe(first())
232232
.subscribe(() => {
@@ -245,7 +245,7 @@ export class IgxGridNavigationService {
245245
`${cellSelector}[data-visibleIndex="${visibleColumnIndex}"]`);
246246
cells[0].focus();
247247
} else {
248-
this.grid.nativeElement.focus({ preventScroll: true });
248+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
249249
this.grid.verticalScrollContainer.scrollTo(0);
250250
this.grid.verticalScrollContainer.onChunkLoad
251251
.pipe(first()).subscribe(() => {
@@ -265,7 +265,7 @@ export class IgxGridNavigationService {
265265
`${cellSelector}[data-visibleIndex="${visibleColumnIndex}"]`);
266266
cells[cells.length - 1].focus();
267267
} else {
268-
this.grid.nativeElement.focus({ preventScroll: true });
268+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
269269
this.grid.verticalScrollContainer.scrollTo(this.grid.verticalScrollContainer.igxForOf.length - 1);
270270
this.grid.verticalScrollContainer.onChunkLoad
271271
.pipe(first()).subscribe(() => {
@@ -285,7 +285,7 @@ export class IgxGridNavigationService {
285285
const containerTopOffset = parseInt(this.verticalDisplayContainerElement.style.top, 10);
286286
if (!rowElement.previousElementSibling ||
287287
rowElement.previousElementSibling.offsetTop < Math.abs(containerTopOffset)) {
288-
this.grid.nativeElement.focus({ preventScroll: true });
288+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
289289
this.grid.verticalScrollContainer.scrollTo(currentRowIndex - 1);
290290
this.grid.verticalScrollContainer.onChunkLoad
291291
.pipe(first())
@@ -322,7 +322,7 @@ export class IgxGridNavigationService {
322322
const targetEndTopOffset = rowElement.nextElementSibling ?
323323
rowElement.nextElementSibling.offsetTop + rowHeight + parseInt(this.verticalDisplayContainerElement.style.top, 10) :
324324
containerHeight + rowHeight;
325-
this.grid.nativeElement.focus({ preventScroll: true });
325+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
326326
if (containerHeight && containerHeight < targetEndTopOffset) {
327327
const nextIndex = currentRowIndex + 1;
328328
this.grid.verticalScrollContainer.scrollTo(nextIndex);
@@ -366,7 +366,7 @@ export class IgxGridNavigationService {
366366
if (!horizontalScroll.clientWidth || parseInt(horizontalScroll.scrollLeft, 10) <= 1 || this.grid.pinnedColumns.length) {
367367
this.navigateTop(0);
368368
} else {
369-
this.grid.nativeElement.focus({ preventScroll: true });
369+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
370370
this.horizontalScroll(this.grid.dataRowList.first.index).scrollTo(0);
371371
this.grid.parentVirtDir.onChunkLoad
372372
.pipe(first())
@@ -385,7 +385,7 @@ export class IgxGridNavigationService {
385385
const rowIndex = parseInt(rows[rows.length - 1].getAttribute('data-rowIndex'), 10);
386386
this.onKeydownEnd(rowIndex);
387387
} else {
388-
this.grid.nativeElement.focus({ preventScroll: true });
388+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
389389
this.grid.verticalScrollContainer.scrollTo(this.grid.verticalScrollContainer.igxForOf.length - 1);
390390
this.grid.verticalScrollContainer.onChunkLoad
391391
.pipe(first()).subscribe(() => {
@@ -598,7 +598,7 @@ export class IgxGridNavigationService {
598598
public performHorizontalScrollToCell(
599599
rowIndex: number, visibleColumnIndex: number, isSummary: boolean = false, cb?: () => void) {
600600
const unpinnedIndex = this.getColumnUnpinnedIndex(visibleColumnIndex);
601-
this.grid.nativeElement.focus({ preventScroll: true });
601+
this.getFocusableGrid().nativeElement.focus({ preventScroll: true });
602602
this.grid.parentVirtDir.onChunkLoad
603603
.pipe(first())
604604
.subscribe(() => {
@@ -614,6 +614,10 @@ export class IgxGridNavigationService {
614614
this.horizontalScroll(rowIndex).scrollTo(unpinnedIndex);
615615
}
616616

617+
protected getFocusableGrid() {
618+
return this.grid;
619+
}
620+
617621
protected getRowByIndex(index, selector = this.getRowSelector()) {
618622
return this.grid.nativeElement.querySelector(
619623
`${selector}[data-rowindex="${index}"]`);

projects/igniteui-angular/src/lib/grids/grid/grid.multi-row-layout.integration.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,42 @@ describe('IgxGrid - multi-row-layout Integration - ', () => {
11101110
expect(groupRowBlocks[0].nativeElement.style.gridTemplateColumns).toEqual('200px 200px 650px 50px 100px 200px');
11111111
});
11121112
});
1113+
1114+
describe('Selection ', () => {
1115+
beforeEach(async(() => {
1116+
fixture = TestBed.createComponent(ColumnLayoutGroupingTestComponent);
1117+
fixture.detectChanges();
1118+
grid = fixture.componentInstance.grid;
1119+
colGroups = fixture.componentInstance.colGroups;
1120+
}));
1121+
1122+
it('should return correct selected data via getSelectedData API.', () => {
1123+
const selectedData1 = [{
1124+
ID: 'ALFKI',
1125+
CompanyName: 'Alfreds Futterkiste',
1126+
ContactName: 'Maria Anders',
1127+
ContactTitle: 'Sales Representative'
1128+
}];
1129+
const selectedData2 = [{
1130+
PostalCode: '05021',
1131+
City: 'México D.F.',
1132+
Country: 'Mexico',
1133+
Address: 'Avda. de la Constitución 2222'
1134+
}];
1135+
let cell = grid.getCellByColumn(0, 'CompanyName');
1136+
UIInteractions.clickElement(cell);
1137+
fixture.detectChanges();
1138+
1139+
expect(grid.getSelectedData()).toEqual(selectedData1);
1140+
1141+
cell = grid.getCellByColumn(1, 'City');
1142+
UIInteractions.clickElement(cell);
1143+
fixture.detectChanges();
1144+
1145+
expect(grid.getSelectedData()).toEqual(selectedData2);
1146+
});
1147+
});
1148+
11131149
});
11141150

11151151
@Component({

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { first } from 'rxjs/operators';
44
import { FilterMode } from '../grid-base.component';
55
import { IgxColumnComponent } from '../../grids/column.component';
66
import { ISelectionNode } from '../../core/grid-selection';
7+
import { isIE } from '../../core/utils';
78

89
export class IgxHierarchicalGridNavigationService extends IgxGridNavigationService {
910
public grid: IgxHierarchicalGridComponent;
@@ -174,6 +175,18 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
174175
if (cells.length > 0) { cells[cells.length - 1].focus(); }
175176
});
176177
}
178+
} else if (this.grid.parent !== null) {
179+
const childContainer = this.grid.nativeElement.parentNode.parentNode;
180+
const diff =
181+
childContainer.getBoundingClientRect().bottom - this.grid.rootGrid.tbody.nativeElement.getBoundingClientRect().bottom;
182+
const endIsVisible = diff < 0;
183+
const scrollable = this.getNextScrollableDown(this.grid);
184+
if (!endIsVisible) {
185+
this.scrollGrid(scrollable.grid, diff,
186+
() => super.navigateBottom(visibleColumnIndex));
187+
} else {
188+
super.navigateBottom(visibleColumnIndex);
189+
}
177190
} else {
178191
super.navigateBottom(visibleColumnIndex);
179192
}
@@ -423,6 +436,10 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
423436
}
424437
}
425438

439+
public getFocusableGrid() {
440+
return (isIE() && this.grid.rootGrid) ? this.grid.rootGrid : this.grid;
441+
}
442+
426443
private getLastGridElem(trContainer) {
427444
const children = trContainer.children;
428445
const closestChild = children[children.length - 1].children[0].children[0];
@@ -720,7 +737,7 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
720737
grid.dataRowList.toArray()[0].virtDirRow.scrollTo(unpinnedIndex);
721738
}
722739
private scrollGrid(grid, target, callBackFunc) {
723-
grid.nativeElement.focus({ preventScroll: true });
740+
this.getFocusableGrid().nativeElement.focus({preventScroll: true});
724741
requestAnimationFrame(() => {
725742
if (typeof target === 'number') {
726743
grid.verticalScrollContainer.addScrollTop(target);

0 commit comments

Comments
 (0)