Skip to content

Commit ed72c8c

Browse files
authored
Merge pull request #7328 from IgniteUI/mkirova/fix-7315
fix(igxGrid): Update getNextDataRowIndex so that it can work with pin…
2 parents 4f7cb50 + 39e26eb commit ed72c8c

File tree

3 files changed

+131
-5
lines changed

3 files changed

+131
-5
lines changed

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

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5795,10 +5795,48 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
57955795
if (currentRowIndex < 0 || (currentRowIndex === 0 && previous) || (currentRowIndex >= this.dataView.length - 1 && !previous)) {
57965796
return currentRowIndex;
57975797
}
5798-
const rows = previous ? this.dataView.slice(0, currentRowIndex).reverse() :
5799-
this.dataView.slice(currentRowIndex + 1, this.dataView.length);
5800-
const nextRow = rows.find(rec => !rec.expression && !rec.summaries && !rec.childGridsData && !rec.detailsData);
5801-
return nextRow ? this.dataView.indexOf(nextRow) : currentRowIndex;
5798+
// find next/prev record that is editable.
5799+
const nextRowIndex = previous ? this.findPrevEditableDataRowIndex(currentRowIndex) :
5800+
this.dataView.findIndex((rec, index) =>
5801+
index > currentRowIndex && this.isEditableDataRecordAtIndex(index));
5802+
return nextRowIndex !== -1 ? nextRowIndex : currentRowIndex ;
5803+
}
5804+
5805+
/**
5806+
* Returns the previous editable row index or -1 if no such row is found.
5807+
* @param currentIndex The index of the current editable record.
5808+
*/
5809+
private findPrevEditableDataRowIndex(currentIndex): number {
5810+
let i = this.dataView.length;
5811+
while (i--) {
5812+
if (i < currentIndex && this.isEditableDataRecordAtIndex(i)) {
5813+
return i;
5814+
}
5815+
}
5816+
return -1;
5817+
}
5818+
5819+
5820+
/**
5821+
* Returns if the record at the specified data view index is a an editable data record.
5822+
* If record is group rec, summary rec, child rec, ghost rec. etc. it is not editable.
5823+
* @param dataViewIndex The index of that record in the data view.
5824+
*/
5825+
private isEditableDataRecordAtIndex(dataViewIndex) {
5826+
const rec = this.dataView[dataViewIndex];
5827+
return !rec.expression && !rec.summaries && !rec.childGridsData && !rec.detailsData &&
5828+
!this.isGhostRecordAtIndex(dataViewIndex);
5829+
}
5830+
5831+
/**
5832+
* Returns if the record at the specified data view index is a ghost.
5833+
* If record is pinned but is not in pinned area then it is a ghost record.
5834+
* @param dataViewIndex The index of that record in the data view.
5835+
*/
5836+
private isGhostRecordAtIndex(dataViewIndex) {
5837+
const isPinned = this.isRecordPinned(this.dataView[dataViewIndex]);
5838+
const isInPinnedArea = this.isRecordPinnedByViewIndex(dataViewIndex);
5839+
return isPinned && !isInPinnedArea;
58025840
}
58035841

58045842
private isValidPosition(rowIndex, colIndex): boolean {

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,94 @@ describe('Row Pinning #grid', () => {
842842
});
843843
});
844844

845+
describe(' Cell Editing', () => {
846+
847+
beforeEach(() => {
848+
fix = TestBed.createComponent(GridRowPinningComponent);
849+
fix.detectChanges();
850+
// enable cell editing for column
851+
grid = fix.componentInstance.instance;
852+
grid.getColumnByName('CompanyName').editable = true;
853+
});
854+
855+
it('should enter edit mode for the next editable cell when tabbing.', () => {
856+
const gridContent = GridFunctions.getGridContent(fix);
857+
grid.getRowByIndex(0).pin();
858+
fix.detectChanges();
859+
grid.getRowByIndex(3).pin();
860+
fix.detectChanges();
861+
862+
const firstEditable = grid.getCellByColumn(0, 'CompanyName');
863+
const secondEditable = grid.getCellByColumn(1, 'CompanyName');
864+
const thirdEditable = grid.getCellByColumn(3, 'CompanyName');
865+
const fourthEditable = grid.getCellByColumn(5, 'CompanyName');
866+
867+
// enter edit mode for pinned row
868+
UIInteractions.simulateDoubleClickAndSelectEvent(firstEditable);
869+
fix.detectChanges();
870+
871+
expect(firstEditable.editMode).toBeTruthy();
872+
873+
// press tab on edited cell
874+
UIInteractions.triggerEventHandlerKeyDown('tab', gridContent);
875+
fix.detectChanges();
876+
877+
expect(firstEditable.editMode).toBeFalsy();
878+
expect(secondEditable.editMode).toBeTruthy();
879+
880+
// press tab on edited cell
881+
UIInteractions.triggerEventHandlerKeyDown('tab', gridContent);
882+
fix.detectChanges();
883+
884+
expect(secondEditable.editMode).toBeFalsy();
885+
expect(thirdEditable.editMode).toBeTruthy();
886+
887+
UIInteractions.triggerEventHandlerKeyDown('tab', gridContent);
888+
fix.detectChanges();
889+
890+
expect(thirdEditable.editMode).toBeFalsy();
891+
expect(fourthEditable.editMode).toBeTruthy();
892+
});
893+
it('should enter edit mode for the previous editable cell when shift+tabbing.', () => {
894+
const gridContent = GridFunctions.getGridContent(fix);
895+
grid.getRowByIndex(0).pin();
896+
fix.detectChanges();
897+
grid.getRowByIndex(3).pin();
898+
fix.detectChanges();
899+
900+
const firstEditable = grid.getCellByColumn(0, 'CompanyName');
901+
const secondEditable = grid.getCellByColumn(1, 'CompanyName');
902+
const thirdEditable = grid.getCellByColumn(3, 'CompanyName');
903+
const fourthEditable = grid.getCellByColumn(5, 'CompanyName');
904+
905+
// enter edit mode for unpinned row
906+
UIInteractions.simulateDoubleClickAndSelectEvent(fourthEditable);
907+
fix.detectChanges();
908+
909+
expect(fourthEditable.editMode).toBeTruthy();
910+
// press shift+tab on edited cell
911+
UIInteractions.triggerEventHandlerKeyDown('tab', gridContent, false, true);
912+
fix.detectChanges();
913+
914+
expect(fourthEditable.editMode).toBeFalsy();
915+
expect(thirdEditable.editMode).toBeTruthy();
916+
917+
// press shift+tab on edited cell
918+
UIInteractions.triggerEventHandlerKeyDown('tab', gridContent, false, true);
919+
fix.detectChanges();
920+
921+
expect(thirdEditable.editMode).toBeFalsy();
922+
expect(secondEditable.editMode).toBeTruthy();
923+
924+
// press shift+tab on edited cell
925+
UIInteractions.triggerEventHandlerKeyDown('tab', gridContent, false, true);
926+
fix.detectChanges();
927+
928+
expect(secondEditable.editMode).toBeFalsy();
929+
expect(firstEditable.editMode).toBeTruthy();
930+
});
931+
});
932+
845933
describe(' Navigation', () => {
846934
let gridContent: DebugElement;
847935

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<button igxButton="raised" (click)="togglePinRow(2)">Pin/Unpin third row'</button>
1313
</div>
1414
<igx-grid [pinning]="pinningConfig" #grid1 [data]="data" [width]="'800px'" [height]="'500px'" [rowSelection]="selectionMode">
15-
<igx-column *ngFor="let c of columns" [sortable]="true" [field]="c.field" [header]="c.field" [width]="c.width" [pinned]='c.pinned'
15+
<igx-column *ngFor="let c of columns" [editable] = true [sortable]="true" [field]="c.field" [header]="c.field" [width]="c.width" [pinned]='c.pinned'
1616
[hidden]='c.hidden'>
1717
</igx-column>
1818
</igx-grid>

0 commit comments

Comments
 (0)