Skip to content

Commit 668b954

Browse files
authored
Merge pull request #12198 from IgniteUI/mkirova/expose-rowdrag-template-inputs
feat(igxGrid): Add template Inputs for row drag templates.
2 parents cf50d28 + 4b88bd6 commit 668b954

File tree

3 files changed

+101
-8
lines changed

3 files changed

+101
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5-
65
## 15.0.0
76

87
### New Features
98
- `igxGrid` - exposing new Input properties:
9+
- `dragGhostCustomTemplate` - Gets/Sets the custom template used for row drag.
10+
- `dragIndicatorIconTemplate` - Gets/Sets the custom template used for row drag indicator.
1011
- `detailTemplate` - Gets/Sets the master-detail template.
1112

1213
## 14.2.0

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,33 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
12271227
@ContentChildren(IgxRowDragGhostDirective, { read: TemplateRef, descendants: false })
12281228
public dragGhostCustomTemplates: QueryList<TemplateRef<IgxGridRowDragGhostContext>>;
12291229

1230+
1231+
/**
1232+
* Gets the custom template, if any, used for row drag ghost.
1233+
*/
1234+
@Input()
1235+
public get dragGhostCustomTemplate() {
1236+
return this._dragGhostCustomTemplate || this.dragGhostCustomTemplates.first;
1237+
}
1238+
1239+
/**
1240+
* Sets a custom template for the row drag ghost.
1241+
*```html
1242+
* <ng-template #template igxRowDragGhost>
1243+
* <igx-icon>menu</igx-icon>
1244+
* </ng-template>
1245+
* ```
1246+
* ```typescript
1247+
* @ViewChild("'template'", {read: TemplateRef })
1248+
* public template: TemplateRef<any>;
1249+
* this.grid.dragGhostCustomTemplate = this.template;
1250+
* ```
1251+
*/
1252+
public set dragGhostCustomTemplate(template: TemplateRef<IgxGridRowDragGhostContext>) {
1253+
this._dragGhostCustomTemplate = template;
1254+
}
1255+
1256+
12301257
/**
12311258
* @hidden @internal
12321259
*/
@@ -2399,10 +2426,24 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
23992426
/**
24002427
* The custom template, if any, that should be used when rendering the row drag indicator icon
24012428
*/
2429+
@Input()
24022430
public get dragIndicatorIconTemplate(): TemplateRef<IgxGridEmptyTemplateContext> {
24032431
return this._customDragIndicatorIconTemplate || this.dragIndicatorIconTemplates.first;
24042432
}
24052433

2434+
/**
2435+
* Sets a custom template that should be used when rendering the row drag indicator icon.
2436+
*```html
2437+
* <ng-template #template igxDragIndicatorIcon>
2438+
* <igx-icon>expand_less</igx-icon>
2439+
* </ng-template>
2440+
* ```
2441+
* ```typescript
2442+
* @ViewChild("'template'", {read: TemplateRef })
2443+
* public template: TemplateRef<any>;
2444+
* this.grid.dragIndicatorIconTemplate = this.template;
2445+
* ```
2446+
*/
24062447
public set dragIndicatorIconTemplate(val: TemplateRef<IgxGridEmptyTemplateContext>) {
24072448
this._customDragIndicatorIconTemplate = val;
24082449
}
@@ -2873,6 +2914,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
28732914
private _filteredSortedData = null;
28742915

28752916
private _customDragIndicatorIconTemplate: TemplateRef<IgxGridEmptyTemplateContext>;
2917+
private _dragGhostCustomTemplate: TemplateRef<IgxGridRowDragGhostContext>;
28762918
private _cdrRequests = false;
28772919
private _resourceStrings;
28782920
private _emptyGridMessage = null;
@@ -3763,11 +3805,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
37633805
* @internal
37643806
*/
37653807
public getDragGhostCustomTemplate() {
3766-
if (this.dragGhostCustomTemplates && this.dragGhostCustomTemplates.first) {
3767-
return this.dragGhostCustomTemplates.first;
3768-
}
37693808

3770-
return null;
3809+
return this.dragGhostCustomTemplate;
37713810
}
37723811

37733812
/**

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, DebugElement, QueryList } from '@angular/core';
1+
import { Component, ViewChild, DebugElement, QueryList, TemplateRef } from '@angular/core';
22
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
33
import { FormsModule } from '@angular/forms';
44
import { By } from '@angular/platform-browser';
@@ -420,10 +420,12 @@ describe('Row Drag Tests #grid', () => {
420420
]
421421
});
422422
}));
423-
it('should correctly create custom ghost element', () => {
423+
beforeEach(fakeAsync(() => {
424424
fixture = TestBed.createComponent(IgxGridRowCustomGhostDraggableComponent);
425425
grid = fixture.componentInstance.instance;
426426
fixture.detectChanges();
427+
}));
428+
it('should correctly create custom ghost element', () => {
427429
dropAreaElement = fixture.debugElement.query(By.css(CSS_CLASS_DROPPABLE_AREA)).nativeElement;
428430
rows = grid.rowList.toArray();
429431
dragIndicatorElements = fixture.debugElement.queryAll(By.css(CSS_CLASS_DRAG_INDICATOR));
@@ -449,6 +451,42 @@ describe('Row Drag Tests #grid', () => {
449451

450452
const ghostText = document.getElementsByClassName(CSS_CLASS_GHOST_ROW)[0].textContent;
451453
expect(ghostText).toEqual(' Moving a row! ');
454+
pointerUpEvent = UIInteractions.createPointerEvent('pointerup', dropPoint);
455+
rowDragDirective.onPointerUp(pointerUpEvent);
456+
});
457+
458+
it('should allow setting custom drag icon and ghost element via Input.', () => {
459+
dropAreaElement = fixture.debugElement.query(By.css(CSS_CLASS_DROPPABLE_AREA)).nativeElement;
460+
grid.dragIndicatorIconTemplate = fixture.componentInstance.rowDragTemplate;
461+
grid.dragGhostCustomTemplate = fixture.componentInstance.rowDragGhostTemplate;
462+
fixture.detectChanges();
463+
rows = grid.rowList.toArray();
464+
dragIndicatorElements = fixture.debugElement.queryAll(By.css(CSS_CLASS_DRAG_INDICATOR));
465+
dragIndicatorElement = dragIndicatorElements[2].nativeElement;
466+
dragRows = fixture.debugElement.queryAll(By.directive(IgxRowDragDirective));
467+
rowDragDirective = dragRows[1].injector.get(IgxRowDragDirective);
468+
469+
expect(dragIndicatorElement.textContent.trim()).toBe('expand_less');
470+
471+
startPoint = UIInteractions.getPointFromElement(dragIndicatorElement);
472+
movePoint = UIInteractions.getPointFromElement(rows[4].nativeElement);
473+
dropPoint = UIInteractions.getPointFromElement(dropAreaElement);
474+
pointerDownEvent = UIInteractions.createPointerEvent('pointerdown', startPoint);
475+
pointerMoveEvent = UIInteractions.createPointerEvent('pointermove', movePoint);
476+
477+
rowDragDirective.onPointerDown(pointerDownEvent);
478+
rowDragDirective.onPointerMove(pointerMoveEvent);
479+
pointerMoveEvent = UIInteractions.createPointerEvent('pointermove', dropPoint);
480+
rowDragDirective.onPointerMove(pointerMoveEvent);
481+
const ghostElements: HTMLCollection = document.getElementsByClassName(CSS_CLASS_GHOST_ROW);
482+
expect(ghostElements.length).toEqual(1);
483+
484+
const ghostText = document.getElementsByClassName(CSS_CLASS_GHOST_ROW)[0].textContent;
485+
expect(ghostText.trim()).toEqual('CUSTOM');
486+
487+
pointerUpEvent = UIInteractions.createPointerEvent('pointerup', dropPoint);
488+
rowDragDirective.onPointerUp(pointerUpEvent);
489+
452490
});
453491
});
454492
});
@@ -751,7 +789,7 @@ describe('Row Drag Tests #grid', () => {
751789

752790
const ghostElements = document.getElementsByClassName(CSS_CLASS_GHOST_ROW);
753791
const ghostElement = ghostElements[0];
754-
expect(ghostElements.length).toEqual(2);
792+
expect(ghostElements.length).toEqual(1);
755793
expect(ghostElement.classList.contains(CSS_CLASS_SELECTED_ROW)).toBeFalsy();
756794

757795
pointerMoveEvent = UIInteractions.createPointerEvent('pointermove', dropPoint);
@@ -1228,12 +1266,27 @@ export class IgxGridRowDraggableComponent extends DataParent {
12281266
<div #nonDroppableArea class="non-droppable-area"
12291267
[ngStyle]="{width:'100px', height:'100px', backgroundColor:'yellow'}">
12301268
</div>
1269+
1270+
<ng-template #rowDragGhostTemplate let-data igxRowDragGhost>
1271+
<div class="dragGhost">
1272+
CUSTOM
1273+
</div>
1274+
</ng-template>
1275+
<ng-template #rowDragTemplate let-data igxDragIndicatorIcon>
1276+
<igx-icon>expand_less</igx-icon>
1277+
</ng-template>
12311278
`
12321279
})
12331280
export class IgxGridRowCustomGhostDraggableComponent extends DataParent {
12341281
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
12351282
public instance: IgxGridComponent;
12361283

1284+
@ViewChild('rowDragGhostTemplate', {read: TemplateRef, static: true })
1285+
public rowDragGhostTemplate: TemplateRef<any>;
1286+
1287+
@ViewChild('rowDragTemplate', {read: TemplateRef, static: true })
1288+
public rowDragTemplate: TemplateRef<any>;
1289+
12371290
@ViewChild('dropArea', { read: IgxDropDirective, static: true })
12381291
public dropArea: IgxDropDirective;
12391292

0 commit comments

Comments
 (0)