Skip to content

Commit fd237e1

Browse files
committed
feat(row-drag): Adding igxDragCustomGhost directive #6081
1 parent 7d9ca30 commit fd237e1

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

projects/igniteui-angular/src/lib/directives/drag-drop/drag-drop.directive.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export class IgxDragLocation {
151151
})
152152
export class IgxDragDirective implements AfterContentInit, OnDestroy {
153153

154+
protected ghostContext: any = null;
155+
154156
/**
155157
* - Save data inside the `igxDrag` directive. This can be set when instancing `igxDrag` on an element.
156158
* ```html
@@ -1099,7 +1101,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
10991101

11001102
let dynamicGhostRef;
11011103
if (this.ghostTemplate) {
1102-
dynamicGhostRef = this.viewContainer.createEmbeddedView(this.ghostTemplate);
1104+
dynamicGhostRef = this.viewContainer.createEmbeddedView(this.ghostTemplate, this.ghostContext);
11031105
this.ghostElement = dynamicGhostRef.rootNodes[0];
11041106
} else {
11051107
this.ghostElement = node ? node.cloneNode(true) : this.element.nativeElement.cloneNode(true);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="igx-grid__row-indentation igx-grid__row-indentation--level-{{grid.groupingExpressions.length}}"></div>
33
</ng-container>
44
<ng-container *ngIf="rowDraggable">
5-
<div [class]="resolveDragIndicatorClasses" [igxRowDrag]="this" (click)="$event.stopPropagation()">
5+
<div [class]="resolveDragIndicatorClasses" [igxRowDrag]="this" (click)="$event.stopPropagation()" [ghostTemplate]="this.grid.dragGhostCustomTemplate">
66
<ng-container *ngTemplateOutlet="this.grid.dragIndicatorIconTemplate ? this.grid.dragIndicatorIconTemplate : this.grid.dragIndicatorIconBase"></ng-container>
77
</div>
88
</ng-container>

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IgxColumnResizingService } from '../resizing/resizing.service';
2222
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
2323
import { IgxGridSelectionService, IgxGridCRUDService } from '../selection/selection.service';
2424
import { IgxForOfSyncService, IgxForOfScrollSyncService } from '../../directives/for-of/for_of.sync.service';
25-
import { IgxDragIndicatorIconDirective } from '../row-drag.directive';
25+
import { IgxDragIndicatorIconDirective, IgxDragCustomGhostDirective } from '../row-drag.directive';
2626
import { IgxGridMRLNavigationService } from '../grid-mrl-navigation.service';
2727
import { FilterMode } from '../common/enums';
2828
import { GridType } from '../common/grid.interface';
@@ -491,6 +491,27 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
491491
@ContentChild(IgxDragIndicatorIconDirective, { read: TemplateRef, static: false })
492492
public dragIndicatorIconTemplate: TemplateRef<any> = null;
493493

494+
/**
495+
* The custom drag ghost, if any, that should be used when rendering the drag ghost
496+
*
497+
* ```typescript
498+
* // Set in typescript
499+
* const myCustomGhostTemplate: TemplateRef<any> = myComponent.customGhostTemplate;
500+
* myComponent.dragGhostCustomTemplate = myCustomGhostTemplate;
501+
* ```
502+
* ```html
503+
* <!-- Set in markup -->
504+
* <igx-grid #grid>
505+
* ...
506+
* <ng-template igxDragCustomGhost>
507+
* <div class="dragGhost">Custom drag ghost!</div>
508+
* </ng-template>
509+
* </igx-grid>
510+
* ```
511+
*/
512+
@ContentChild(IgxDragCustomGhostDirective, { read: TemplateRef, static: false })
513+
public dragGhostCustomTemplate: TemplateRef<any> = null;
514+
494515
@ViewChildren(IgxGridGroupByRowComponent, { read: IgxGridGroupByRowComponent })
495516
private _groupsRowList: QueryList<IgxGridGroupByRowComponent>;
496517

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
100100
protected createGhost(pageX, pageY) {
101101
this.row.grid.endEdit(true);
102102
this.row.grid.markForCheck();
103+
this.ghostContext = {
104+
$implicit: this.row.rowData,
105+
data: this.row.rowData,
106+
grid: this.row.grid
107+
};
103108
super.createGhost(pageX, pageY, this.row.nativeElement);
104109

105110
const ghost = this.ghostElement;
@@ -152,10 +157,20 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
152157
export class IgxDragIndicatorIconDirective {
153158
}
154159

160+
/**
161+
* @hidden
162+
*/
163+
@Directive({
164+
selector: '[igxDragCustomGhost]'
165+
})
166+
167+
export class IgxDragCustomGhostDirective {
168+
}
169+
155170
@NgModule({
156-
declarations: [IgxRowDragDirective, IgxDragIndicatorIconDirective],
171+
declarations: [IgxRowDragDirective, IgxDragIndicatorIconDirective, IgxDragCustomGhostDirective],
157172
entryComponents: [],
158-
exports: [IgxRowDragDirective, IgxDragIndicatorIconDirective],
173+
exports: [IgxRowDragDirective, IgxDragIndicatorIconDirective, IgxDragCustomGhostDirective],
159174
imports: []
160175
})
161176

src/app/grid-row-draggable/grid-row-draggable.sample.html

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
<igx-icon fontSet="material" [igxRowDrag]="cell.row">info</igx-icon>
1414
</ng-template>
1515
</igx-column>
16+
<ng-template let-data igxDragCustomGhost>
17+
<div class="dragGhost">
18+
<igx-icon fontSet="material"></igx-icon>
19+
Moving {{data.ProductName}}!
20+
</div>
21+
</ng-template>
1622
</igx-grid>
1723
<igx-grid #grid2 igxDrop [data]="newData" [primaryKey]="'ProductID'"
1824
[displayDensity]="density" [width]="'500px'" [height]="'600px'" [emptyGridTemplate]="dragHereTemplate"

0 commit comments

Comments
 (0)