Skip to content

Commit f0aacc7

Browse files
authored
Merge branch '8.2.x' into mkirova/fix-throttle
2 parents 925bcc4 + 5b7bcba commit f0aacc7

File tree

9 files changed

+119
-18
lines changed

9 files changed

+119
-18
lines changed

projects/igniteui-angular/src/lib/directives/template-outlet/template_outlet.directive.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export class IgxTemplateOutletDirective implements OnChanges {
3232
@Output()
3333
public onCachedViewLoaded = new EventEmitter<ICachedViewLoadedEventArgs>();
3434

35+
@Output()
36+
public onBeforeViewDetach = new EventEmitter<IViewChangeEventArgs>();
37+
3538
constructor(public _viewContainerRef: ViewContainerRef, private _zone: NgZone, public cdr: ChangeDetectorRef) {
3639
}
3740

@@ -65,6 +68,7 @@ export class IgxTemplateOutletDirective implements OnChanges {
6568
private _recreateView() {
6669
// detach old and create new
6770
if (this._viewRef) {
71+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
6872
this._viewContainerRef.detach(this._viewContainerRef.indexOf(this._viewRef));
6973
}
7074
if (this.igxTemplateOutlet) {
@@ -91,9 +95,11 @@ export class IgxTemplateOutletDirective implements OnChanges {
9195
if (view !== this._viewRef) {
9296
if (owner._viewContainerRef.indexOf(view) !== -1) {
9397
// detach in case view it is attached somewhere else at the moment.
98+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
9499
owner._viewContainerRef.detach(owner._viewContainerRef.indexOf(view));
95100
}
96101
if (this._viewRef && this._viewContainerRef.indexOf(this._viewRef) !== -1) {
102+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
97103
this._viewContainerRef.detach(this._viewContainerRef.indexOf(this._viewRef));
98104
}
99105
this._viewRef = view;
@@ -111,6 +117,7 @@ export class IgxTemplateOutletDirective implements OnChanges {
111117
// if view exists, but template has been changed and there is a view in the cache with the related template
112118
// then detach old view and insert the stored one with the matching template
113119
// after that update its context.
120+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
114121
this._viewContainerRef.detach(this._viewContainerRef.indexOf(this._viewRef));
115122
this._viewRef = cachedView;
116123
const oldContext = this._cloneContext(cachedView.context);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6040,6 +6040,20 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
60406040
return this.cellSelection !== GridSelectionMode.none;
60416041
}
60426042

6043+
/** @hidden */
6044+
public viewDetachHandler(args: ICachedViewLoadedEventArgs) {
6045+
const context = args.view.context;
6046+
if (context['templateID'] === 'dataRow') {
6047+
// some browsers (like FireFox and Edge) do not trigger onBlur when the focused element is detached from DOM
6048+
// hence we need to trigger it manually when cell is detached.
6049+
const row = this.getRowByIndex(context.index);
6050+
const focusedCell = row.cells.find(x => x.focused);
6051+
if (focusedCell) {
6052+
focusedCell.onBlur();
6053+
}
6054+
}
6055+
}
6056+
60436057
/**
60446058
* @hidden
60456059
*/

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,34 @@ export class IgxGridNavigationService {
167167
}
168168

169169
public movePreviousEditable(rowIndex: number, currentColumnVisibleIndex: number) {
170-
const prevEditableColumnIndex = this.findNextEditable(MoveDirection.LEFT, currentColumnVisibleIndex - 1);
171-
if (prevEditableColumnIndex === -1 && this.grid.rowEditTabs.length) {
172-
// TODO: make gridAPI visible for internal use and remove cast to any
173-
(this.grid as any).gridAPI.submit_value();
174-
this.grid.rowEditTabs.last.element.nativeElement.focus();
175-
return;
170+
let prevEditableColumnIndex = this.findNextEditable(MoveDirection.LEFT, currentColumnVisibleIndex - 1);
171+
if (prevEditableColumnIndex === -1) {
172+
if (this.grid.rowEditTabs.length) {
173+
// TODO: make gridAPI visible for internal use and remove cast to any
174+
(this.grid as any).gridAPI.submit_value();
175+
this.grid.rowEditTabs.last.element.nativeElement.focus();
176+
return;
177+
} else {
178+
// In case when row edit template is empty select last editable cell
179+
prevEditableColumnIndex = this.grid.lastEditableColumnIndex;
180+
}
181+
176182
}
177183
this.focusEditableTarget(rowIndex, prevEditableColumnIndex);
178184
}
179185

180186
public moveNextEditable(rowIndex: number, currentColumnVisibleIndex: number) {
181-
const nextEditableColumnIndex = this.findNextEditable(MoveDirection.RIGHT, currentColumnVisibleIndex + 1);
182-
if (nextEditableColumnIndex === -1 && this.grid.rowEditTabs.length) {
183-
// TODO: make gridAPI visible for internal use and remove cast to any
184-
(this.grid as any).gridAPI.submit_value();
185-
this.grid.rowEditTabs.first.element.nativeElement.focus();
186-
return;
187+
let nextEditableColumnIndex = this.findNextEditable(MoveDirection.RIGHT, currentColumnVisibleIndex + 1);
188+
if (nextEditableColumnIndex === -1) {
189+
if ( this.grid.rowEditTabs.length) {
190+
// TODO: make gridAPI visible for internal use and remove cast to any
191+
(this.grid as any).gridAPI.submit_value();
192+
this.grid.rowEditTabs.first.element.nativeElement.focus();
193+
return;
194+
} else {
195+
// In case when row edit template is empty select first editable cell
196+
nextEditableColumnIndex = this.grid.firstEditableColumnIndex;
197+
}
187198
}
188199
this.focusEditableTarget(rowIndex, nextEditableColumnIndex);
189200
}

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
IgxGridWithEditingAndFeaturesComponent,
2424
IgxGridRowEditingWithoutEditableColumnsComponent,
2525
IgxGridCustomOverlayComponent,
26-
IgxGridRowEditingWithFeaturesComponent
26+
IgxGridRowEditingWithFeaturesComponent,
27+
IgxGridEmptyRowEditTemplateComponent
2728
} from '../../test-utils/grid-samples.spec';
2829
import { IgxGridTestComponent } from './grid.component.spec';
2930

@@ -45,7 +46,8 @@ describe('IgxGrid - Row Editing #grid', () => {
4546
IgxGridRowEditingWithoutEditableColumnsComponent,
4647
IgxGridTestComponent,
4748
IgxGridCustomOverlayComponent,
48-
IgxGridRowEditingWithFeaturesComponent
49+
IgxGridRowEditingWithFeaturesComponent,
50+
IgxGridEmptyRowEditTemplateComponent
4951
],
5052
imports: [
5153
NoopAnimationsModule, IgxGridModule]
@@ -1912,7 +1914,7 @@ describe('IgxGrid - Row Editing #grid', () => {
19121914

19131915
expect(parseInt(GridFunctions.getRowEditingBannerText(fix), 10)).toEqual(0);
19141916
fix.componentInstance.cellInEditMode.editValue = 'Spiro';
1915-
fix.componentInstance.moveNext(true);
1917+
UIInteractions.triggerKeyDownWithBlur('tab', cell.nativeElement, true);
19161918
tick(16);
19171919
fix.detectChanges();
19181920

@@ -1923,6 +1925,41 @@ describe('IgxGrid - Row Editing #grid', () => {
19231925
expect(grid.endEdit).toHaveBeenCalled();
19241926
expect(grid.endEdit).toHaveBeenCalledTimes(1);
19251927
}));
1928+
1929+
it('Empty template', fakeAsync(() => {
1930+
const fix = TestBed.createComponent(IgxGridEmptyRowEditTemplateComponent);
1931+
fix.detectChanges();
1932+
tick(16);
1933+
1934+
const grid = fix.componentInstance.grid;
1935+
let cell = grid.getCellByColumn(0, 'ProductName');
1936+
UIInteractions.triggerKeyDownEvtUponElem('f2', cell.nativeElement, true);
1937+
1938+
fix.detectChanges();
1939+
tick(16);
1940+
1941+
cell.editValue = 'Spiro';
1942+
UIInteractions.triggerKeyDownEvtUponElem('tab', cell.nativeElement, true);
1943+
1944+
fix.detectChanges();
1945+
tick(16);
1946+
fix.detectChanges();
1947+
tick(16);
1948+
1949+
expect(cell.editMode).toBe(false);
1950+
cell = grid.getCellByColumn(0, 'ReorderLevel');
1951+
expect(cell.editMode).toBe(true);
1952+
1953+
UIInteractions.triggerKeyDownEvtUponElem('tab', cell.nativeElement, true, false, true);
1954+
fix.detectChanges();
1955+
tick(16);
1956+
fix.detectChanges();
1957+
tick(16);
1958+
1959+
expect(cell.editMode).toBe(false);
1960+
cell = grid.getCellByColumn(0, 'ProductName');
1961+
expect(cell.editMode).toBe(true);
1962+
}));
19261963
});
19271964

19281965
describe('Transaction', () => {

projects/igniteui-angular/src/lib/grids/grid/grid.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@
131131
<ng-template
132132
[igxTemplateOutlet]='isGroupByRecord(rowData) ? group_template : isSummaryRow(rowData) ? summary_template : record_template'
133133
[igxTemplateOutletContext]='getContext(rowData, rowIndex)'
134-
(onCachedViewLoaded)='cachedViewLoaded($event)'>
134+
(onCachedViewLoaded)='cachedViewLoaded($event)'
135+
(onBeforeViewDetach)='viewDetachHandler($event)' >
135136
</ng-template>
136137
</ng-template>
137138
<ng-container *ngTemplateOutlet="template"></ng-container>

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<ng-template
9494
[igxTemplateOutlet]='(isHierarchicalRecord(rowData) ? hierarchical_record_template : (isChildGridRecord(rowData) && isExpanded(rowData) ? child_record_template : hierarchical_record_template))'
9595
[igxTemplateOutletContext]='getContext(rowData)' (onViewCreated)='viewCreatedHandler($event)'
96-
(onViewMoved)='viewMovedHandler($event)' (onCachedViewLoaded)='cachedViewLoaded($event)'></ng-template>
96+
(onViewMoved)='viewMovedHandler($event)' (onCachedViewLoaded)='cachedViewLoaded($event)' (onBeforeViewDetach)='viewDetachHandler($event)'></ng-template>
9797
<!-- <ng-container *igxTemplateOutlet="(isHierarchicalRecord(rowData) ? hierarchical_record_template : (isChildGridRecord(rowData) && isExpanded(rowData) ? child_record_template : hierarchical_record_template)); context: getContext(rowData)"></ng-container> -->
9898
</ng-template>
9999
<ng-template #hierarchical_record_template let-rowIndex="index" let-rowData>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IRowDragEndEventArgs, IRowDragStartEventArgs } from './grid-base.compon
44
import { KEYS } from '../core/utils';
55
import { fromEvent, Subscription } from 'rxjs';
66
import { IgxRowComponent, IgxGridBaseComponent, IGridDataBindable } from './grid';
7+
import { IgxHierarchicalRowComponent } from './hierarchical-grid/hierarchical-row.component';
78

89

910
const ghostBackgroundClass = 'igx-grid__tr--ghost';
@@ -106,6 +107,15 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
106107
};
107108
super.createGhost(pageX, pageY, this.row.nativeElement);
108109

110+
// check if there is an expander icon and create the ghost at the corresponding position
111+
if (this.isHierarchicalGrid) {
112+
const row = this.row as IgxHierarchicalRowComponent;
113+
if (row.expander) {
114+
const expanderWidth = row.expander.nativeElement.getBoundingClientRect().width;
115+
this._ghostHostX += expanderWidth;
116+
}
117+
}
118+
109119
const ghost = this.ghostElement;
110120

111121
const gridRect = this.row.grid.nativeElement.getBoundingClientRect();
@@ -144,6 +154,10 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
144154
}
145155
this.endDragging();
146156
}
157+
158+
private get isHierarchicalGrid() {
159+
return this.row.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
160+
}
147161
}
148162

149163
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595

9696
<ng-template [igxTemplateOutlet]='isSummaryRow(rowData) ? summary_template : record_template'
9797
[igxTemplateOutletContext]='getContext(rowData, rowIndex)'
98-
(onCachedViewLoaded)='cachedViewLoaded($event)'>
98+
(onCachedViewLoaded)='cachedViewLoaded($event)'
99+
(onBeforeViewDetach)='viewDetachHandler($event)'>
99100
</ng-template>
100101
</ng-template>
101102
<ng-container *ngTemplateOutlet="template"></ng-container>

projects/igniteui-angular/src/lib/test-utils/grid-samples.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,22 @@ export class IgxGridCustomOverlayComponent extends BasicGridComponent {
14191419
}
14201420
}
14211421

1422+
@Component({
1423+
template: `
1424+
<igx-grid #grid [data]="data" [primaryKey]="'ProductID'" width="700px" height="400px" [rowEditable]="true">
1425+
<igx-column field="ProductID" header="Product ID"></igx-column>
1426+
<igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" [editable]="true" width="100px"></igx-column>
1427+
<igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="150px"></igx-column>
1428+
<igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="150px" [editable]="false"></igx-column>
1429+
<ng-template igxRowEdit >
1430+
</ng-template>
1431+
</igx-grid>
1432+
`
1433+
})
1434+
export class IgxGridEmptyRowEditTemplateComponent extends BasicGridComponent {
1435+
public data = SampleTestData.foodProductData();
1436+
}
1437+
14221438
@Component({
14231439
template: `
14241440
<igx-grid #grid [data]="data" [primaryKey]="'ProductID'" width="900px" height="900px" [rowEditable]="true"

0 commit comments

Comments
 (0)