Skip to content

Commit ef772ce

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Fix for API usage when primaryKey is set.
1 parent c30ed80 commit ef772ce

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,7 +4033,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
40334033
* @param index The index at which to insert the row in the pinned collection.
40344034
*/
40354035
public pinRow(rowID, index?): boolean {
4036-
if (this.pinnedRecords.indexOf(rowID) !== -1) {
4036+
const rec = this.primaryKey ? this.gridAPI.get_rec_by_id(rowID) : rowID;
4037+
if (this.pinnedRecords.indexOf(rec) !== -1) {
40374038
return false;
40384039
}
40394040
const row = this.gridAPI.get_row_by_key(rowID);
@@ -4046,7 +4047,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
40464047
};
40474048
this.onRowPinning.emit(eventArgs);
40484049

4049-
this.pinnedRecords.splice(eventArgs.insertAtIndex || this.pinnedRecords.length, 0, rowID);
4050+
this.pinnedRecords.splice(eventArgs.insertAtIndex || this.pinnedRecords.length, 0, rec);
40504051
this._pipeTrigger++;
40514052
if (this.gridAPI.grid) {
40524053
this.notifyChanges(true);
@@ -4064,7 +4065,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
40644065
* @param rowID The row id - primaryKey value or the data record instance.
40654066
*/
40664067
public unpinRow(rowID) {
4067-
if (this.pinnedRecords.indexOf(rowID) === -1) {
4068+
const rec = this.primaryKey ? this.gridAPI.get_rec_by_id(rowID) : rowID;
4069+
const index = this.pinnedRecords.indexOf(rec);
4070+
if (index === -1) {
40684071
return false;
40694072
}
40704073
const row = this.gridAPI.get_row_by_key(rowID);
@@ -4074,7 +4077,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
40744077
row: row
40754078
};
40764079
this.onRowPinning.emit(eventArgs);
4077-
const index = this.pinnedRecords.indexOf(rowID);
40784080
this.pinnedRecords.splice(index, 1);
40794081
this._pipeTrigger++;
40804082
if (this.gridAPI.grid) {

projects/igniteui-angular/src/lib/grids/row.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class IgxRowDirective<T extends IgxGridBaseDirective & GridType> implemen
6565
* ```
6666
*/
6767
public get pinned(): boolean {
68-
return this.grid.pinnedRecords.indexOf(this.rowID) !== -1;
68+
return this.grid.pinnedRecords.indexOf(this.rowData) !== -1;
6969
}
7070
/**
7171
* Sets whether the row is pinned.

src/app/grid-row-pinning/grid-row-pinning.sample.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<igx-switch (change)='onRowChange()' style="padding-left: 10px"> Bottom Row Pinning toggle</igx-switch>
99
<igx-switch (change)='onChange()' style="padding-left: 10px"> Right Column Pinning toggle</igx-switch>
1010
</div>
11-
<igx-grid [allowFiltering]='true' [pinning]="pinningConfig" [showToolbar]='true' [columnPinning]='true' #grid1 [data]="data" [width]="'800px'" [height]="'500px'" [rowSelectable]="false">
11+
<igx-grid [allowFiltering]='true' [primaryKey]='"ID"' [pinning]="pinningConfig" [showToolbar]='true' [columnPinning]='true' #grid1 [data]="data" [width]="'800px'" [height]="'500px'" [rowSelectable]="false">
1212
<igx-column width='70px' [filterable]='false'>
1313
<ng-template igxCell let-cell="cell" let-val>
1414
<igx-icon class="pin-icon" (mousedown)="togglePining(cell.row, $event)">
15-
{{isRowPinned(cell.row) ? 'lock' : 'lock_open'}}
15+
{{cell.row.pinned ? 'lock' : 'lock_open'}}
1616
</igx-icon>
1717
</ng-template>
1818
</igx-column>

src/app/grid-row-pinning/grid-row-pinning.sample.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,11 @@ export class GridRowPinningSampleComponent implements OnInit {
9090

9191
togglePining(row: IgxGridRowComponent, event) {
9292
event.preventDefault();
93-
if(this.isRowPinned(row)) {
93+
if(row.pinned) {
9494
row.unpin();
9595
} else {
9696
row.pin();
9797
}
9898
}
9999

100-
isRowPinned(row) {
101-
return this.grid1.pinnedRecords.indexOf(row.rowID) !== -1;
102-
}
103-
104100
}

0 commit comments

Comments
 (0)