Skip to content

Commit 764fc44

Browse files
authored
Merge branch 'master' into mkirova/fix-6396
2 parents 1a840d1 + b3b4917 commit 764fc44

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
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

@@ -66,6 +69,7 @@ export class IgxTemplateOutletDirective implements OnChanges {
6669
const prevIndex = this._viewRef ? this._viewContainerRef.indexOf(this._viewRef) : -1;
6770
// detach old and create new
6871
if (prevIndex !== -1) {
72+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
6973
this._viewContainerRef.detach(prevIndex);
7074
}
7175
if (this.igxTemplateOutlet) {
@@ -92,9 +96,11 @@ export class IgxTemplateOutletDirective implements OnChanges {
9296
if (view !== this._viewRef) {
9397
if (owner._viewContainerRef.indexOf(view) !== -1) {
9498
// detach in case view it is attached somewhere else at the moment.
99+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
95100
owner._viewContainerRef.detach(owner._viewContainerRef.indexOf(view));
96101
}
97102
if (this._viewRef && this._viewContainerRef.indexOf(this._viewRef) !== -1) {
103+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
98104
this._viewContainerRef.detach(this._viewContainerRef.indexOf(this._viewRef));
99105
}
100106
this._viewRef = view;
@@ -113,6 +119,7 @@ export class IgxTemplateOutletDirective implements OnChanges {
113119
// then detach old view and insert the stored one with the matching template
114120
// after that update its context.
115121
if (this._viewContainerRef.length > 0) {
122+
this.onBeforeViewDetach.emit({ owner: this, view: this._viewRef, context: this.igxTemplateOutletContext });
116123
this._viewContainerRef.detach(this._viewContainerRef.indexOf(this._viewRef));
117124
}
118125

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6012,6 +6012,19 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
60126012
return this.cellSelection !== GridSelectionMode.none;
60136013
}
60146014

6015+
public viewDetachHandler(args: ICachedViewLoadedEventArgs) {
6016+
const context = args.view.context;
6017+
if (context['templateID'] === 'dataRow') {
6018+
// some browsers (like FireFox and Edge) do not trigger onBlur when the focused element is detached from DOM
6019+
// hence we need to trigger it manually when cell is detached.
6020+
const row = this.getRowByIndex(context.index);
6021+
const focusedCell = row.cells.find(x => x.focused);
6022+
if (focusedCell) {
6023+
focusedCell.onBlur();
6024+
}
6025+
}
6026+
}
6027+
60156028
/**
60166029
* @hidden
60176030
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
[igxTemplateOutletContext]='getContext(rowData, rowIndex)'
123123
(onCachedViewLoaded)='cachedViewLoaded($event)'
124124
(onViewCreated)='viewCreatedHandler($event)'
125-
(onViewMoved)='viewMovedHandler($event)'>
125+
(onViewMoved)='viewMovedHandler($event)'
126+
(onBeforeViewDetach)='viewDetachHandler($event)'>
126127
</ng-template>
127128
</ng-template>
128129
<ng-template #record_template let-rowIndex="index" let-rowData>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
<ng-template
109109
[igxTemplateOutlet]='(isHierarchicalRecord(rowData) ? hierarchical_record_template : (isChildGridRecord(rowData) && isExpanded(rowData) ? child_record_template : hierarchical_record_template))'
110110
[igxTemplateOutletContext]='getContext(rowData)' (onViewCreated)='viewCreatedHandler($event)'
111-
(onViewMoved)='viewMovedHandler($event)' (onCachedViewLoaded)='cachedViewLoaded($event)'></ng-template>
111+
(onViewMoved)='viewMovedHandler($event)' (onCachedViewLoaded)='cachedViewLoaded($event)'
112+
(onBeforeViewDetach)='viewDetachHandler($event)'></ng-template>
112113
<!-- <ng-container *igxTemplateOutlet="(isHierarchicalRecord(rowData) ? hierarchical_record_template : (isChildGridRecord(rowData) && isExpanded(rowData) ? child_record_template : hierarchical_record_template)); context: getContext(rowData)"></ng-container> -->
113114
</ng-template>
114115
<ng-container *ngTemplateOutlet="template"></ng-container>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fromEvent, Subscription } from 'rxjs';
55
import { IgxRowDirective, IgxGridBaseDirective } from './grid';
66
import { IRowDragStartEventArgs, IRowDragEndEventArgs } from './common/events';
77
import { GridType } from './common/grid.interface';
8+
import { IgxHierarchicalRowComponent } from './hierarchical-grid/hierarchical-row.component';
89

910

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

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

112122
const gridRect = this.row.grid.nativeElement.getBoundingClientRect();
@@ -145,6 +155,10 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
145155
}
146156
this.endDragging();
147157
}
158+
159+
private get isHierarchicalGrid() {
160+
return this.row.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
161+
}
148162
}
149163

150164
/**

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>

0 commit comments

Comments
 (0)