Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ export var registerConfig = [
methods: [
"getRowByIndex",
"getRowByKey",
"getSelectedData",
"getCellByColumn",
"getCellByKey",
"pinRow",
Expand Down Expand Up @@ -631,7 +632,6 @@ export var registerConfig = [
"clearCellSelection",
"selectRange",
"getSelectedRanges",
"getSelectedData",
"selectedColumns",
"selectColumns",
"deselectColumns",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7433,7 +7433,7 @@ export abstract class IgxGridBaseDirective implements GridType,
const keysAndData = [];
const activeEl = this.selectionService.activeElement;

if (this.type === 'hierarchical') {
if (this.type === 'hierarchical' && source === this.filteredSortedData) {
const expansionRowIndexes = [];
for (const [key, value] of this.expansionStates.entries()) {
if (value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,22 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
.reduce((a, b) => a.concat(b), []);
}

/**
* Returns an array of the current cell selection.
*/
public override getSelectedData(formatters = false, headers = false): any[] {
Comment on lines +805 to +808
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, edit the JSDoc comment to be as complete as the overrides in the grid and tree-grid as an example.

const source: any[] = [];
this.dataView.forEach((record) => {
if (this.isChildGridRecord(record)) {
source.push(null);
return;
}
const rowData = record as any;
source.push(this.isGhostRecord(rowData) || this.isRecordMerged(rowData) ? rowData.recordRef : rowData);
});
Comment on lines +810 to +817
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The forEach record parameter could be typed as any instead of declaring a separate variable just for the sake of casting in this case:

  this.dataView.forEach((record: any) => {  
            if (this.isChildGridRecord(record)) {  
                source.push(null);  
                return;  
            }  
            source.push(this.isGhostRecord(record) || this.isRecordMerged(record) ? record.recordRef : record);  

Btw, again referring to the existing overrides in the grid and tree-grid, there is this nested process function pattern, which you could consider. Functionally it would be the same, just mentioning it for the sake of consistency.

return this.extractDataFromSelection(source, formatters, headers);
}

/**
* Returns a `CellType` object that matches the conditions.
*
Expand Down Expand Up @@ -1165,7 +1181,6 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
super.initColumns(collection, cb);
}


protected override setupColumns() {
if (this.parentIsland && this.parentIsland.childColumns.length > 0 && !this.autoGenerate) {
this.createColumnsList(this.parentIsland.childColumns.toArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IgxColumnMovingDragDirective, IgxGridNavigationService } from 'igniteui
import { IgxHierarchicalRowComponent } from './hierarchical-row.component';
import { take } from 'rxjs/operators';
import {
IgxHierarchicalGridEmptyDataExportComponent,
IgxHierarchicalGridTestBaseComponent,
IgxHierarchicalGridTestCustomToolbarComponent,
IgxHierarchicalGridTestInputPaginatorComponent,
Expand Down Expand Up @@ -35,6 +36,7 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
IgxHierarchicalGridEmptyDataExportComponent,
IgxHierarchicalGridTestBaseComponent,
IgxHierarchicalGridTestCustomToolbarComponent,
IgxHierarchicalGridWithTransactionProviderComponent,
Expand Down Expand Up @@ -162,6 +164,39 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
expect(fChildCell.selected).toBeFalsy();
expect(fCell.selected).toBeTruthy();
}));

it('should not copy the previous row value from an expanded parent row', fakeAsync(() => {
const singersFixture = TestBed.createComponent(IgxHierarchicalGridEmptyDataExportComponent);
const singersData = SampleTestData.hierarchicalGridSingersFullData();
(singersFixture.componentInstance as { data: unknown[] }).data = singersData;
singersFixture.detectChanges();

const grid = singersFixture.componentInstance.hGrid;

const previousArtist = singersData[1].Artist;
const targetArtist = singersData[2].Artist;
const targetRow = grid.dataRowList.toArray()
.find(row => row.data.Artist === targetArtist) as IgxHierarchicalRowComponent | undefined;

expect(targetRow).toBeDefined();
targetRow!.toggle();
tick(DEBOUNCE_TIME);
singersFixture.detectChanges();

grid.selectRange({
rowStart: targetRow!.index,
rowEnd: targetRow!.index,
columnStart: 'Artist',
columnEnd: 'Artist'
});
singersFixture.detectChanges();

expect(targetRow!.expanded).toBeTruthy();

const selectedData = grid.getSelectedData();
expect(selectedData).toEqual([{ Artist: targetArtist }]);
expect(selectedData[0].Artist).not.toBe(previousArtist);
}));
});

describe('Updating', () => {
Expand Down
Loading