Skip to content

Commit

Permalink
Merge pull request #11279 from IgniteUI/mkirova/fix-10118
Browse files Browse the repository at this point in the history
fix(igxGrid): Minor fix and refactor for row adding APIs.
  • Loading branch information
dkamburov authored Mar 25, 2022
2 parents 62ff80c + 5de9152 commit 47bafd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5964,18 +5964,22 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
console.warn('The record cannot be added as a child to an unspecified record.');
return;
}
index = 0;
index = null;
} else {
// find the index of the record with that PK
index = this.gridAPI.get_rec_index_by_id(rowID, this.dataView);
rowID = index;
if (index === -1) {
console.warn('No row with the specified ID was found.');
return;
}
}

this._addRowForIndex(index, asChild);
}

protected _addRowForIndex(index: number, asChild?: boolean) {
if (!this.dataView.length) {
this.beginAddRowForIndex(rowID, asChild);
this.beginAddRowForIndex(index, asChild);
return;
}
// check if the index is valid - won't support anything outside the data view
Expand All @@ -5987,13 +5991,13 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
this.verticalScrollContainer.chunkLoad
.pipe(first(), takeUntil(this.destroy$))
.subscribe(() => {
this.beginAddRowForIndex(rowID, asChild);
this.beginAddRowForIndex(index, asChild);
});
this.navigateTo(index);
this.notifyChanges(true);
return;
}
this.beginAddRowForIndex(rowID, asChild);
this.beginAddRowForIndex(index, asChild);
} else {
console.warn('The row with the specified PK or index is outside of the current data view.');
}
Expand All @@ -6014,7 +6018,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
if (index === 0) {
return this.beginAddRowById(null);
}
return this.beginAddRowById(this.gridAPI.get_rec_id_by_index(index - 1, this.dataView));
return this._addRowForIndex(index - 1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
if (index === null || index < 0) {
return this.beginAddRowById(null, asChild);
}
return this.beginAddRowById(this.gridAPI.get_rec_id_by_index(index, this.dataView), asChild);
return this._addRowForIndex(index - 1, asChild);
}

/**
Expand Down

0 comments on commit 47bafd5

Please sign in to comment.