Skip to content

Commit 9ac7b4a

Browse files
authored
Merge pull request #7255 from IgniteUI/action-strip-jump-to
feat(RowPinning): Initial implementation of jump to disabled row grid action.
2 parents 28a7218 + 4f4fc09 commit 9ac7b4a

File tree

9 files changed

+99
-40
lines changed

9 files changed

+99
-40
lines changed

projects/igniteui-angular/src/lib/action-strip/grid-actions/grid-pinning-actions.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<ng-container *ngIf="isRowContext">
2+
<button *ngIf="inPinnedArea && pinnedTop" igxRipple igxButton="icon" (click)="scrollToRow($event)">
3+
<igx-icon fontSet="filtering-icons" name="jump_down"></igx-icon>
4+
</button>
5+
<button *ngIf="inPinnedArea && !pinnedTop" igxRipple igxButton="icon" (click)="scrollToRow($event)">
6+
<igx-icon fontSet="filtering-icons" name="jump_up"></igx-icon>
7+
</button>
28
<button *ngIf="!pinned" igxRipple igxButton="icon" (click)="pin($event)">
39
<igx-icon fontSet="filtering-icons" name="pin"></igx-icon>
410
</button>

projects/igniteui-angular/src/lib/action-strip/grid-actions/grid-pinning-actions.component.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IgxGridModule, IgxGridComponent } from '../../grids/grid';
77
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
88
import { By } from '@angular/platform-browser';
99
import { IgxActionStripModule } from '../action-strip.module';
10+
import { wait } from '../../test-utils/ui-interactions.spec';
1011

1112

1213
describe('igxGridPinningActions #grid ', () => {
@@ -57,8 +58,22 @@ describe('igxGridPinningActions #grid ', () => {
5758
expect(grid.pinnedRows.length).toBe(0);
5859
});
5960

60-
it('should allow navigating to disabled row in unpinned area', () => {
61-
pending('implementation');
61+
it('should allow navigating to disabled row in unpinned area', async() => {
62+
grid.pinRow('FAMIA');
63+
fixture.detectChanges();
64+
65+
actionStrip.show(grid.pinnedRows[0]);
66+
fixture.detectChanges();
67+
68+
const jumpIcon = fixture.debugElement.query(By.css(`igx-icon[name=jump_down]`));
69+
jumpIcon.parent.triggerEventHandler('click', new Event('click'));
70+
await wait();
71+
fixture.detectChanges();
72+
await wait();
73+
fixture.detectChanges();
74+
75+
const secondToLastVisible = grid.rowList.toArray()[grid.rowList.length - 2];
76+
expect(secondToLastVisible.rowID).toEqual('FAMIA');
6277
});
6378
});
6479

projects/igniteui-angular/src/lib/action-strip/grid-actions/grid-pinning-actions.component.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ export class IgxGridPinningActionsComponent extends IgxGridActionsBaseDirective
3535
return context && context.pinned;
3636
}
3737

38+
/**
39+
* Getter to know if the row is in pinned and ghost
40+
* @hidden
41+
* @internal
42+
*/
43+
get inPinnedArea(): boolean {
44+
if (!this.isRow(this.strip.context)) {
45+
return;
46+
}
47+
const context = this.strip.context;
48+
return this.pinned && !context.disabled;
49+
}
50+
51+
/**
52+
* Getter to know if the row pinning is set to top or bottom
53+
* @hidden
54+
* @internal
55+
*/
56+
get pinnedTop(): boolean {
57+
if (!this.isRow(this.strip.context)) {
58+
return;
59+
}
60+
return this.strip.context.grid.isRowPinningToTop;
61+
}
62+
3863
/**
3964
* Pin the row according to the context.
4065
* @example
@@ -75,6 +100,16 @@ export class IgxGridPinningActionsComponent extends IgxGridActionsBaseDirective
75100
this.strip.hide();
76101
}
77102

103+
public scrollToRow(event) {
104+
if (event) {
105+
event.stopPropagation();
106+
}
107+
const context = this.strip.context;
108+
const grid = context.grid;
109+
grid.scrollTo(context.rowData, 0);
110+
this.strip.hide();
111+
}
112+
78113
private renderIcons(): void {
79114
if (!this.isRow(this.strip.context)) {
80115
return;

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,9 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
831831
// need to adjust the offsets so that item is last in view.
832832
const updatesToIndex = this._adjustToIndex - this.state.startIndex + 1;
833833
const sumDiffs = diffs.slice(0, updatesToIndex).reduce(reducer);
834-
const currOffset = parseInt(this.dc.instance._viewContainer.element.nativeElement.style.top, 10);
835-
this.dc.instance._viewContainer.element.nativeElement.style.top = (currOffset - sumDiffs) + 'px';
834+
if (sumDiffs !== 0) {
835+
this.addScrollTop(sumDiffs);
836+
}
836837
this._adjustToIndex = null;
837838
}
838839
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export class IgxGridRowPinningPipe implements PipeTransform {
229229

230230
if (grid.hasPinnedRecords && isPinned) {
231231
const result = collection.filter(rec => grid.isRecordPinned(rec));
232-
result.sort((rec1, rec2) => grid.pinRecordIndex(rec1) - grid.pinRecordIndex(rec2));
232+
result.sort((rec1, rec2) => grid.getInitialPinnedIndex(rec1) - grid.getInitialPinnedIndex(rec2));
233233
return result;
234234
}
235235

projects/igniteui-angular/src/lib/grids/filtering/svgIcons.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,17 @@ export default [
228228
<rect x="7.5" y="7.5" width="3.75" height="3.75"/>
229229
<rect x="12.75" y="7.5" width="3.75" height="3.75"/>
230230
</svg>`
231+
},
232+
{
233+
name: 'jump_up',
234+
value: `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
235+
<path d="M6 8l4 4H7c0 3.31 2.69 6 6 6 1.01 0 1.97-.25 2.8-.7l1.46 1.46A7.93 7.93 0 0113 20c-4.42 0-8-3.58-8-8H2l4-4zm15-5v2H5V3h16z"/>
236+
</svg>`
237+
},
238+
{
239+
name: 'jump_down',
240+
value: `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
241+
<path d="M21 19v2H5v-2h16zM13 4c1.57 0 3.03.46 4.26 1.24L15.8 6.7A5.87 5.87 0 0013 6c-3.31 0-6 2.69-6 6h3l-4 4-4-4h3c0-4.42 3.58-8 8-8z"/>
242+
</svg>`
231243
}
232244
];

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,9 +2449,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
24492449
*/
24502450
protected destroy$ = new Subject<any>();
24512451

2452-
protected _filteredSortedPinnedData;
2453-
protected _filteredSortedUnpinnedData;
2454-
protected _filteredPinnedData;
2452+
protected _filteredSortedPinnedData: any[];
2453+
protected _filteredSortedUnpinnedData: any[];
2454+
protected _filteredPinnedData: any[];
24552455

24562456
/**
24572457
* @hidden
@@ -2711,15 +2711,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
27112711
});
27122712
}
27132713

2714-
/**
2715-
* @hidden
2716-
* @internal
2717-
*/
2718-
public isRecordPinned(rec) {
2719-
const id = this.primaryKey ? rec[this.primaryKey] : rec;
2720-
return this._pinnedRecordIDs.indexOf(id) !== -1;
2721-
}
2722-
27232714
/**
27242715
* Returns whether the record is pinned or not.
27252716
*
@@ -2737,9 +2728,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
27372728
* Returns whether the record is pinned or not.
27382729
*
27392730
* @param rowIndex Index of the record in the `filteredSortedData` collection.
2740-
*
2741-
* @hidden
2742-
* @internal
27432731
*/
27442732
public isRecordPinnedByIndex(rowIndex: number) {
27452733
return this.hasPinnedRecords && (this.isRowPinningToTop && rowIndex < this._filteredSortedPinnedData.length) ||
@@ -2750,8 +2738,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
27502738
* @hidden
27512739
* @internal
27522740
*/
2753-
public pinRecordIndex(rec) {
2754-
const id = this.primaryKey ? rec[this.primaryKey] : rec;
2741+
public isRecordPinned(rec) {
2742+
return this.getInitialPinnedIndex(rec) !== -1;
2743+
}
2744+
2745+
/**
2746+
* @hidden
2747+
* @internal
2748+
* Returns the record index in order of pinning by the user. Does not consider sorting/filtering.
2749+
*/
2750+
public getInitialPinnedIndex(rec) {
2751+
const id = this.gridAPI.get_row_id(rec);
27552752
return this._pinnedRecordIDs.indexOf(id);
27562753
}
27572754

@@ -3015,12 +3012,12 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
30153012
*/
30163013
public setFilteredSortedData(data, pinned: boolean) {
30173014
data = data || [];
3018-
if (this._pinnedRecordIDs.length > 0 && pinned) {
3015+
if (this.pinnedRecordsCount > 0 && pinned) {
30193016
this._filteredSortedPinnedData = data;
30203017
this.pinnedRecords = data;
30213018
this.filteredSortedData = this.isRowPinningToTop ? [... this._filteredSortedPinnedData, ... this._filteredSortedUnpinnedData] :
30223019
[... this._filteredSortedUnpinnedData, ... this._filteredSortedPinnedData];
3023-
} else if (this._pinnedRecordIDs.length > 0 && !pinned) {
3020+
} else if (this.pinnedRecordsCount > 0 && !pinned) {
30243021
this._filteredSortedUnpinnedData = data;
30253022
} else {
30263023
this.filteredSortedData = data;
@@ -5959,7 +5956,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
59595956
/**
59605957
* @hidden
59615958
*/
5962-
protected scrollTo(row: any | number, column: any | number, inCollection = this.filteredSortedData): void {
5959+
protected scrollTo(row: any | number, column: any | number, inCollection = this._filteredSortedUnpinnedData): void {
59635960
let delayScrolling = false;
59645961

59655962
if (this.paging && typeof (row) !== 'number') {

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.navigation.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,23 @@ describe('IgxHierarchicalGrid Basic Navigation #hGrid', () => {
271271
}));
272272

273273
it('should scroll top of child grid into view when pressing Ctrl + Arrow Up when cell is selected in it.', (async () => {
274-
hierarchicalGrid.verticalScrollContainer.scrollTo(7);
275-
fixture.detectChanges();
276274
await wait(DEBOUNCE_TIME);
275+
fixture.detectChanges();
276+
277277
hierarchicalGrid.verticalScrollContainer.scrollTo(7);
278+
await wait(DEBOUNCE_TIME);
278279
fixture.detectChanges();
280+
hierarchicalGrid.verticalScrollContainer.scrollTo(7);
279281
await wait(DEBOUNCE_TIME);
282+
fixture.detectChanges();
280283

281284
const childGrid = hierarchicalGrid.hgridAPI.getChildGrids(false)[3];
282-
283285
const childLastRowCell = childGrid.dataRowList.toArray()[9].cells.toArray()[0];
284286
const childGridContent = fixture.debugElement.queryAll(By.css(GRID_CONTENT_CLASS))[1];
285287
GridFunctions.focusCell(fixture, childLastRowCell);
286288
fixture.detectChanges();
287289
UIInteractions.triggerEventHandlerKeyDown('arrowup', childGridContent, false, false, true);
290+
await wait(200);
288291
fixture.detectChanges();
289292
await wait(200);
290293
fixture.detectChanges();

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -616,22 +616,12 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
616616
};
617617
}
618618

619-
/**
620-
* @hidden @internal
621-
* This is overwritten because tree grid records have special record format - ITreeGridRecord,
622-
* which already has the rowID in the record object.
623-
*/
624-
public isRecordPinned(rec) {
625-
const id = rec.rowID;
626-
return this._pinnedRecordIDs.indexOf(id) !== -1;
627-
}
628-
629619
/**
630620
* @hidden
631621
* @internal
632622
*/
633-
public pinRecordIndex(rec) {
634-
return super.pinRecordIndex(rec.data);
623+
public getInitialPinnedIndex(rec) {
624+
return this._pinnedRecordIDs.indexOf(rec.rowID);
635625
}
636626

637627
/**

0 commit comments

Comments
 (0)