Skip to content

Commit f59af44

Browse files
MKirovaMKirova
authored andcommitted
feat(igxGrid): Add template Inputs for row drag templates.
1 parent 2ab4d30 commit f59af44

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Ignite UI for Angular Change Log
22

33
All notable changes for each version of this project will be documented in this file.
4+
5+
## 15.0.0
6+
7+
### New Features
8+
- `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.
411
## 14.2.0
512

613
### New Features

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

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,32 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
12081208
@ContentChildren(IgxRowDragGhostDirective, { read: TemplateRef, descendants: false })
12091209
public dragGhostCustomTemplates: QueryList<TemplateRef<any>>;
12101210

1211+
1212+
/**
1213+
* Gets the custom template, if any, used for row drag ghost.
1214+
*/
1215+
public get dragGhostCustomTemplate() {
1216+
return this._dragGhostCustomTemplate || this.dragGhostCustomTemplates.first;
1217+
}
1218+
1219+
/**
1220+
* Sets a custom template for the row drag ghost.
1221+
* * ```html
1222+
* <ng-template #template igxRowDragGhost>
1223+
* <igx-icon>menu</igx-icon>
1224+
* </ng-template>
1225+
* ```
1226+
* ```typescript
1227+
* @ViewChild("'template'", {read: TemplateRef })
1228+
* public template: TemplateRef<any>;
1229+
* this.grid.dragGhostCustomTemplate = this.template;
1230+
* ```
1231+
*/
1232+
public set dragGhostCustomTemplate(template: TemplateRef<any>) {
1233+
this._dragGhostCustomTemplate = template;
1234+
}
1235+
1236+
12111237
/**
12121238
* @hidden @internal
12131239
*/
@@ -2380,10 +2406,24 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
23802406
/**
23812407
* The custom template, if any, that should be used when rendering the row drag indicator icon
23822408
*/
2409+
@Input()
23832410
public get dragIndicatorIconTemplate(): TemplateRef<any> {
23842411
return this._customDragIndicatorIconTemplate || this.dragIndicatorIconTemplates.first;
23852412
}
23862413

2414+
/**
2415+
* Sets a custom template that should be used when rendering the row drag indicator icon.
2416+
* * ```html
2417+
* <ng-template #template igxDragIndicatorIcon>
2418+
* <igx-icon>expand_less</igx-icon>
2419+
* </ng-template>
2420+
* ```
2421+
* ```typescript
2422+
* @ViewChild("'template'", {read: TemplateRef })
2423+
* public template: TemplateRef<any>;
2424+
* this.grid.dragIndicatorIconTemplate = this.template;
2425+
* ```
2426+
*/
23872427
public set dragIndicatorIconTemplate(val: TemplateRef<any>) {
23882428
this._customDragIndicatorIconTemplate = val;
23892429
}
@@ -2854,6 +2894,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
28542894
private _filteredSortedData = null;
28552895

28562896
private _customDragIndicatorIconTemplate: TemplateRef<any>;
2897+
private _dragGhostCustomTemplate: TemplateRef<any>;
28572898
private _cdrRequests = false;
28582899
private _resourceStrings;
28592900
private _emptyGridMessage = null;
@@ -3744,11 +3785,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
37443785
* @internal
37453786
*/
37463787
public getDragGhostCustomTemplate() {
3747-
if (this.dragGhostCustomTemplates && this.dragGhostCustomTemplates.first) {
3748-
return this.dragGhostCustomTemplates.first;
3749-
}
37503788

3751-
return null;
3789+
return this.dragGhostCustomTemplate;
37523790
}
37533791

37543792
/**

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

Lines changed: 50 additions & 1 deletion
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';
@@ -450,6 +450,40 @@ describe('Row Drag Tests #grid', () => {
450450
const ghostText = document.getElementsByClassName(CSS_CLASS_GHOST_ROW)[0].textContent;
451451
expect(ghostText).toEqual(' Moving a row! ');
452452
});
453+
454+
it('should allow setting custom drag icon and ghost element via Input.', () => {
455+
fixture = TestBed.createComponent(IgxGridRowCustomGhostDraggableComponent);
456+
grid = fixture.componentInstance.instance as IgxGridComponent;
457+
fixture.detectChanges();
458+
dropAreaElement = fixture.debugElement.query(By.css(CSS_CLASS_DROPPABLE_AREA)).nativeElement;
459+
grid.dragIndicatorIconTemplate = fixture.componentInstance.rowDragTemplate;
460+
grid.dragGhostCustomTemplate = fixture.componentInstance.rowDragGhostTemplate;
461+
fixture.detectChanges();
462+
rows = grid.rowList.toArray();
463+
dragIndicatorElements = fixture.debugElement.queryAll(By.css(CSS_CLASS_DRAG_INDICATOR));
464+
dragIndicatorElement = dragIndicatorElements[2].nativeElement;
465+
dragRows = fixture.debugElement.queryAll(By.directive(IgxRowDragDirective));
466+
rowDragDirective = dragRows[1].injector.get(IgxRowDragDirective);
467+
468+
expect(dragIndicatorElement.textContent.trim()).toBe('expand_less');
469+
470+
startPoint = UIInteractions.getPointFromElement(dragIndicatorElement);
471+
movePoint = UIInteractions.getPointFromElement(rows[4].nativeElement);
472+
dropPoint = UIInteractions.getPointFromElement(dropAreaElement);
473+
pointerDownEvent = UIInteractions.createPointerEvent('pointerdown', startPoint);
474+
pointerMoveEvent = UIInteractions.createPointerEvent('pointermove', movePoint);
475+
476+
rowDragDirective.onPointerDown(pointerDownEvent);
477+
rowDragDirective.onPointerMove(pointerMoveEvent);
478+
pointerMoveEvent = UIInteractions.createPointerEvent('pointermove', dropPoint);
479+
rowDragDirective.onPointerMove(pointerMoveEvent);
480+
const ghostElements: HTMLCollection = document.getElementsByClassName(CSS_CLASS_GHOST_ROW);
481+
expect(ghostElements.length).toEqual(1);
482+
483+
const ghostText = document.getElementsByClassName(CSS_CLASS_GHOST_ROW)[0].textContent;
484+
expect(ghostText.trim()).toEqual('CUSTOM');
485+
486+
});
453487
});
454488
});
455489

@@ -1228,12 +1262,27 @@ export class IgxGridRowDraggableComponent extends DataParent {
12281262
<div #nonDroppableArea class="non-droppable-area"
12291263
[ngStyle]="{width:'100px', height:'100px', backgroundColor:'yellow'}">
12301264
</div>
1265+
1266+
<ng-template #rowDragGhostTemplate let-data igxRowDragGhost>
1267+
<div class="dragGhost">
1268+
CUSTOM
1269+
</div>
1270+
</ng-template>
1271+
<ng-template #rowDragTemplate let-data igxDragIndicatorIcon>
1272+
<igx-icon>expand_less</igx-icon>
1273+
</ng-template>
12311274
`
12321275
})
12331276
export class IgxGridRowCustomGhostDraggableComponent extends DataParent {
12341277
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
12351278
public instance: IgxGridComponent;
12361279

1280+
@ViewChild('rowDragGhostTemplate', {read: TemplateRef, static: true })
1281+
public rowDragGhostTemplate: TemplateRef<any>;
1282+
1283+
@ViewChild('rowDragTemplate', {read: TemplateRef, static: true })
1284+
public rowDragTemplate: TemplateRef<any>;
1285+
12371286
@ViewChild('dropArea', { read: IgxDropDirective, static: true })
12381287
public dropArea: IgxDropDirective;
12391288

0 commit comments

Comments
 (0)