Skip to content

Commit 079ce60

Browse files
Vasil MihalkovVasil Mihalkov
Vasil Mihalkov
authored and
Vasil Mihalkov
committed
Merge branch 'vmihalkov/search-with-row-pinning' of https://github.com/IgniteUI/igniteui-angular into vmihalkov/search-with-row-pinning
2 parents 79f2bfe + 7cabdd8 commit 079ce60

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ import { IgxColumnComponent } from './columns/column.component';
147147
import { IgxColumnGroupComponent } from './columns/column-group.component';
148148
import { IGridSortingStrategy } from '../data-operations/sorting-strategy';
149149
import { IgxRowDragGhostDirective, IgxDragIndicatorIconDirective } from './row-drag.directive';
150+
import { isNumber } from 'util';
150151

151152
const MINIMUM_COLUMN_WIDTH = 136;
152153
const FILTER_ROW_HEIGHT = 50;
@@ -2675,6 +2676,14 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
26752676
return this._pinnedRecordIDs.length > 0;
26762677
}
26772678

2679+
/**
2680+
* @hidden
2681+
* @internal
2682+
*/
2683+
public get pinnedRecordsCount() {
2684+
return this._pinnedRecordIDs.length;
2685+
}
2686+
26782687
private keydownHandler = (event) => {
26792688
const key = event.key.toLowerCase();
26802689
if ((isNavigationKey(key) && event.keyCode !== 32) || key === 'tab' || key === 'pagedown' || key === 'pageup') {
@@ -4138,7 +4147,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
41384147

41394148
this.endEdit(true);
41404149

4141-
this._pinnedRecordIDs.splice(eventArgs.insertAtIndex || this._pinnedRecordIDs.length, 0, rowID);
4150+
const insertIndex = isNumber(eventArgs.insertAtIndex) ? eventArgs.insertAtIndex : this._pinnedRecordIDs.length;
4151+
this._pinnedRecordIDs.splice(insertIndex, 0, rowID);
41424152
this._pipeTrigger++;
41434153
if (this.gridAPI.grid) {
41444154
this.notifyChanges(true);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ export class IgxGridPagingPipe implements PipeTransform {
103103
if (!this.gridAPI.grid.paging) {
104104
return collection;
105105
}
106-
106+
const _perPage = perPage - this.gridAPI.grid.pinnedRecordsCount;
107107
const state = {
108108
index: page,
109-
recordsPerPage: perPage
109+
recordsPerPage: _perPage
110110
};
111111
DataUtil.correctPagingState(state, collection.data.length);
112112

projects/igniteui-angular/src/lib/grids/grid/row-pinning.spec.ts

+52
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ describe('Row Pinning #grid', () => {
120120
expect(grid.calcHeight - expectedHeight).toBeLessThanOrEqual(1);
121121
});
122122

123+
it('should allow pinning row at specified index via API.', () => {
124+
grid.pinRow(fix.componentInstance.data[1]);
125+
fix.detectChanges();
126+
127+
expect(grid.pinnedRows.length).toBe(1);
128+
expect(grid.pinnedRows[0].rowData).toBe(fix.componentInstance.data[1]);
129+
130+
// pin at index 0
131+
grid.pinRow(fix.componentInstance.data[2], 0);
132+
fix.detectChanges();
133+
134+
expect(grid.pinnedRows.length).toBe(2);
135+
expect(grid.pinnedRows[0].rowData).toBe(fix.componentInstance.data[2]);
136+
expect(grid.pinnedRows[1].rowData).toBe(fix.componentInstance.data[1]);
137+
138+
// pin at index 1
139+
grid.pinRow(fix.componentInstance.data[3], 1);
140+
fix.detectChanges();
141+
142+
expect(grid.pinnedRows.length).toBe(3);
143+
expect(grid.pinnedRows[0].rowData).toBe(fix.componentInstance.data[2]);
144+
expect(grid.pinnedRows[1].rowData).toBe(fix.componentInstance.data[3]);
145+
expect(grid.pinnedRows[2].rowData).toBe(fix.componentInstance.data[1]);
146+
});
147+
123148
it('should emit onRowPinning on pin/unpin.', () => {
124149
spyOn(grid.onRowPinning, 'emit').and.callThrough();
125150

@@ -371,6 +396,33 @@ describe('Row Pinning #grid', () => {
371396
expect(gridFilterData[1].ID).toBe('BERGS');
372397
});
373398

399+
it('should page through unpinned collection with modified pageSize = pageSize - pinnedRows.lenght.', () => {
400+
// pin 2nd row
401+
grid.paging = true;
402+
grid.perPage = 5;
403+
fix.detectChanges();
404+
let row = grid.getRowByIndex(1);
405+
row.pin();
406+
fix.detectChanges();
407+
408+
expect(grid.pinnedRows.length).toBe(1);
409+
let pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
410+
expect(pinRowContainer.length).toBe(1);
411+
412+
expect(grid.dataView.length).toBe(4);
413+
414+
// unpin
415+
row = grid.getRowByIndex(0);
416+
row.unpin();
417+
fix.detectChanges();
418+
419+
expect(grid.pinnedRows.length).toBe(0);
420+
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
421+
expect(pinRowContainer.length).toBe(0);
422+
423+
expect(grid.dataView.length).toBe(5);
424+
});
425+
374426
it('should apply sorting to both pinned and unpinned rows.', () => {
375427
grid.getRowByIndex(1).pin();
376428
grid.getRowByIndex(5).pin();

0 commit comments

Comments
 (0)