diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts b/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
index d0d19f1597c..f362baa37f2 100644
--- a/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
+++ b/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
@@ -2479,15 +2479,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
*/
protected _columnPinning = false;
-
- /**
- * @hidden
- */
- public get pinnedRecords() {
- return this._pinnedRecords;
- }
-
- protected _pinnedRecords = [];
+ protected _pinnedRecordIDs = [];
/**
* @hidden
@@ -2652,6 +2644,32 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
});
}
+ /**
+ * @hidden
+ * @internal
+ */
+ public isRecordPinned(rec) {
+ const id = this.primaryKey ? rec[this.primaryKey] : rec;
+ return this._pinnedRecordIDs.indexOf(id) !== -1;
+ }
+
+ /**
+ * @hidden
+ * @internal
+ */
+ public pinRecordIndex(rec) {
+ const id = this.primaryKey ? rec[this.primaryKey] : rec;
+ return this._pinnedRecordIDs.indexOf(id);
+ }
+
+ /**
+ * @hidden
+ * @internal
+ */
+ public get hasPinnedRecords() {
+ return this._pinnedRecordIDs.length > 0;
+ }
+
private keydownHandler = (event) => {
const key = event.key.toLowerCase();
if ((isNavigationKey(key) && event.keyCode !== 32) || key === 'tab' || key === 'pagedown' || key === 'pageup') {
@@ -4066,8 +4084,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
* @param index The index at which to insert the row in the pinned collection.
*/
public pinRow(rowID: any, index?: number): boolean {
- const rec = this.gridAPI.get_rec_by_id(rowID);
- if (!rec || this.pinnedRecords.indexOf(rec) !== -1 || this.data.indexOf(rec) === -1) {
+ if (this._pinnedRecordIDs.indexOf(rowID) !== -1) {
return false;
}
const row = this.gridAPI.get_row_by_key(rowID);
@@ -4080,7 +4097,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
};
this.onRowPinning.emit(eventArgs);
- this.pinnedRecords.splice(eventArgs.insertAtIndex || this.pinnedRecords.length, 0, rec);
+ this.endEdit(true);
+
+ this._pinnedRecordIDs.splice(eventArgs.insertAtIndex || this._pinnedRecordIDs.length, 0, rowID);
this._pipeTrigger++;
if (this.gridAPI.grid) {
this.notifyChanges(true);
@@ -4098,9 +4117,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
* @param rowID The row id - primaryKey value or the data record instance.
*/
public unpinRow(rowID: any) {
- const rec = this.gridAPI.get_rec_by_id(rowID);
- const index = this.pinnedRecords.indexOf(rec);
- if (index === -1 || !rec) {
+ const index = this._pinnedRecordIDs.indexOf(rowID);
+ if (index === -1) {
return false;
}
const row = this.gridAPI.get_row_by_key(rowID);
@@ -4110,7 +4128,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
row: row
};
this.onRowPinning.emit(eventArgs);
- this.pinnedRecords.splice(index, 1);
+ this.endEdit(true);
+ this._pinnedRecordIDs.splice(index, 1);
this._pipeTrigger++;
if (this.gridAPI.grid) {
this.cdr.detectChanges();
@@ -4121,7 +4140,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
get pinnedRowHeight() {
const containerHeight = this.pinContainer ? this.pinContainer.nativeElement.offsetHeight : 0;
- return this.pinnedRecords.length > 0 ? containerHeight : 0;
+ return this._pinnedRecordIDs.length > 0 ? containerHeight : 0;
}
get totalHeight() {
diff --git a/projects/igniteui-angular/src/lib/grids/grid/grid.component.html b/projects/igniteui-angular/src/lib/grids/grid/grid.component.html
index a861373f3cb..7f09c419813 100644
--- a/projects/igniteui-angular/src/lib/grids/grid/grid.component.html
+++ b/projects/igniteui-angular/src/lib/grids/grid/grid.component.html
@@ -109,8 +109,10 @@
[igxColumnMovingDrop]="headerContainer" [attr.droppable]="true" id="left"
class="igx-grid__scroll-on-drag-pinned" [style.left.px]="pinnedWidth">