Skip to content

Commit 95453c8

Browse files
authored
Merge pull request #7534 from IgniteUI/nrobakova/fix-issue-7528
fix(grid): update getSelectedData method when grid has details
2 parents c437805 + 344dbeb commit 95453c8

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,11 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
10331033
* @inheritdoc
10341034
*/
10351035
getSelectedData(formatters = false, headers = false): any[] {
1036-
if (this.groupingExpressions.length) {
1036+
if (this.groupingExpressions.length || this.hasDetails) {
10371037
const source = [];
10381038

10391039
const process = (record) => {
1040-
if (record.expression || record.summaries) {
1040+
if (record.expression || record.summaries || this.isDetailRecord(record)) {
10411041
source.push(null);
10421042
return;
10431043
}

projects/igniteui-angular/src/lib/grids/grid/grid.master-detail.spec.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,13 @@ describe('IgxGrid Master Detail #grid', () => {
800800
});
801801

802802
describe('Cell Selection', () => {
803-
it('Should exclude expanded detail views when doing range cell selection', fakeAsync(() => {
803+
beforeEach(fakeAsync(() => {
804804
fix = TestBed.createComponent(DefaultGridMasterDetailComponent);
805805
grid = fix.componentInstance.grid;
806806
fix.detectChanges();
807+
}));
808+
809+
it('Should exclude expanded detail views when doing range cell selection', fakeAsync(() => {
807810
grid.expandRow(fix.componentInstance.data[2].ID);
808811
const selectionChangeSpy = spyOn<any>(grid.onRangeSelection, 'emit').and.callThrough();
809812
const startCell = grid.getCellByColumn(1, 'ContactName');
@@ -839,6 +842,22 @@ describe('IgxGrid Master Detail #grid', () => {
839842
expect(selectionChangeSpy).toHaveBeenCalledWith(range);
840843
expect(rowDetail.querySelector('[class*="selected"]')).toBeNull();
841844
}));
845+
846+
it('getSelectedData should return correct values when there are master details', fakeAsync(() => {
847+
const range = { rowStart: 0, rowEnd: 5, columnStart: 'ContactName', columnEnd: 'ContactName' };
848+
const expectedData = [
849+
{ ContactName: 'Maria Anders' },
850+
{ ContactName: 'Ana Trujillo' },
851+
{ ContactName: 'Antonio Moreno' }
852+
];
853+
grid.expandAll();
854+
tick(100);
855+
fix.detectChanges();
856+
857+
grid.selectRange(range);
858+
fix.detectChanges();
859+
expect(grid.getSelectedData()).toEqual(expectedData);
860+
}));
842861
});
843862

844863
describe('Row Selection', () => {
@@ -1081,10 +1100,12 @@ describe('IgxGrid Master Detail #grid', () => {
10811100
describe('GroupBy', () => {
10821101
beforeEach(fakeAsync(() => {
10831102
fix = TestBed.createComponent(DefaultGridMasterDetailComponent);
1084-
fix.componentInstance.columns[0].hasSummary = true;
10851103
fix.detectChanges();
10861104

10871105
grid = fix.componentInstance.grid;
1106+
grid.getColumnByName('ContactName').hasSummary = true;
1107+
fix.detectChanges();
1108+
10881109
grid.summaryCalculationMode = GridSummaryCalculationMode.childLevelsOnly;
10891110
grid.groupingExpressions =
10901111
[{ fieldName: 'CompanyName', dir: SortingDirection.Asc, ignoreCase: false }];
@@ -1173,9 +1194,7 @@ describe('IgxGrid Master Detail #grid', () => {
11731194
template: `
11741195
<igx-grid [data]="data" [width]="width" [height]="height" [primaryKey]="'ID'" [allowFiltering]='true'
11751196
[paging]="paging" [perPage]="perPage" [rowSelection]="rowSelectable">
1176-
<igx-column *ngFor="let c of columns" [field]="c.field" [header]="c.field" [width]="c.width" [dataType]='c.dataType'
1177-
[hidden]='c.hidden' [sortable]="c.sortable" [movable]='c.movable' [groupable]='c.groupable' [editable]="c.editable"
1178-
[hasSummary]="c.hasSummary" [pinned]='c.pinned'>
1197+
<igx-column *ngFor="let c of columns" [field]="c.field" [width]="c.width" [dataType]='c.dataType'>
11791198
</igx-column>
11801199
11811200
<ng-template igxGridDetail let-dataItem>
@@ -1214,9 +1233,7 @@ export class DefaultGridMasterDetailComponent {
12141233
template: `
12151234
<igx-grid [data]="data" [expansionStates]='expStates'
12161235
[width]="width" [height]="height" [primaryKey]="'ID'" [paging]="paging" [rowSelection]="rowSelectable">
1217-
<igx-column *ngFor="let c of columns" [field]="c.field" [header]="c.field" [width]="c.width" [dataType]='c.dataType'
1218-
[hidden]='c.hidden' [sortable]="c.sortable" [movable]='c.movable' [groupable]='c.groupable' [editable]="c.editable"
1219-
[hasSummary]="c.hasSummary" [pinned]='c.pinned'>
1236+
<igx-column *ngFor="let c of columns" [field]="c.field" [header]="c.field" [width]="c.width" [dataType]='c.dataType'>
12201237
</igx-column>
12211238
12221239
<ng-template igxGridDetail let-dataItem>

0 commit comments

Comments
 (0)