Skip to content

Commit bb987c9

Browse files
authored
Merge branch 'master' into mkirova/expose-excel-filtering-template
2 parents 32d4b45 + 015bb9c commit bb987c9

File tree

13 files changed

+327
-48
lines changed

13 files changed

+327
-48
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ All notable changes for each version of this project will be documented in this
88
- `igxGrid` - exposing new Input properties:
99
- `excelStyleHeaderIconTemplate` - Gets/Sets the excel style header icon.
1010
- `groupRowTemplate` - Gets/Sets the template reference for the group row.
11+
- `rowEditActionsTemplate` - Gets/Sets the row edit actions template.
12+
- `rowAddTextTemplate` - Gets/Sets the row add text template.
13+
- `rowEditTextTemplate` - Gets/Sets the row edit text template.
14+
- `dragGhostCustomTemplate` - Gets/Sets the custom template used for row drag.
15+
- `dragIndicatorIconTemplate` - Gets/Sets the custom template used for row drag indicator.
16+
- `detailTemplate` - Gets/Sets the master-detail template.
1117

1218
## 14.2.0
1319

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

Lines changed: 118 additions & 22 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
*/
@@ -1332,18 +1359,90 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
13321359
@ContentChildren(IgxRowEditTextDirective, { descendants: false, read: TemplateRef })
13331360
public rowEditTextDirectives: QueryList<TemplateRef<IgxGridRowEditTextTemplateContext>>;
13341361

1362+
/**
1363+
* Gets the row edit text template.
1364+
*/
1365+
@Input()
1366+
public get rowEditTextTemplate(): TemplateRef<IgxGridRowEditTextTemplateContext> {
1367+
return this._rowEditTextTemplate || this.rowEditTextDirectives.first;
1368+
}
1369+
/**
1370+
* Sets the row edit text template.
1371+
*```html
1372+
* <ng-template #template igxRowEditText let-rowChangesCount>
1373+
* Changes: {{rowChangesCount}}
1374+
* </ng-template>
1375+
* ```
1376+
*```typescript
1377+
* @ViewChild('template', {read: TemplateRef })
1378+
* public template: TemplateRef<any>;
1379+
* this.grid.rowEditTextTemplate = this.template;
1380+
* ```
1381+
*/
1382+
public set rowEditTextTemplate(template: TemplateRef<IgxGridRowEditTextTemplateContext>) {
1383+
this._rowEditTextTemplate = template;
1384+
}
1385+
13351386
/**
13361387
* @hidden @internal
13371388
*/
13381389
@ContentChild(IgxRowAddTextDirective, { read: TemplateRef })
13391390
public rowAddText: TemplateRef<IgxGridEmptyTemplateContext>;
13401391

1392+
/**
1393+
* Gets the row add text template.
1394+
*/
1395+
@Input()
1396+
public get rowAddTextTemplate(): TemplateRef<IgxGridEmptyTemplateContext> {
1397+
return this._rowAddTextTemplate || this.rowAddText;
1398+
}
1399+
/**
1400+
* Sets the row add text template.
1401+
*```html
1402+
* <ng-template #template igxRowAddText>
1403+
* Adding Row
1404+
* </ng-template>
1405+
* ```
1406+
*```typescript
1407+
* @ViewChild('template', {read: TemplateRef })
1408+
* public template: TemplateRef<any>;
1409+
* this.grid.rowAddTextTemplate = this.template;
1410+
* ```
1411+
*/
1412+
public set rowAddTextTemplate(template: TemplateRef<IgxGridEmptyTemplateContext>) {
1413+
this._rowAddTextTemplate = template;
1414+
}
1415+
13411416
/**
13421417
* @hidden @internal
13431418
*/
13441419
@ContentChildren(IgxRowEditActionsDirective, { descendants: false, read: TemplateRef })
13451420
public rowEditActionsDirectives: QueryList<TemplateRef<IgxGridRowEditActionsTemplateContext>>;
13461421

1422+
/**
1423+
* Gets the row edit actions template.
1424+
*/
1425+
@Input()
1426+
public get rowEditActionsTemplate(): TemplateRef<IgxGridRowEditActionsTemplateContext> {
1427+
return this._rowEditActionsTemplate || this.rowEditActionsDirectives.first;
1428+
}
1429+
/**
1430+
* Sets the row edit actions template.
1431+
*```html
1432+
* <ng-template #template igxRowEditActions let-endRowEdit>
1433+
* <button igxButton igxRowEditTabStop (click)="endRowEdit(false)">Cancel</button>
1434+
* <button igxButton igxRowEditTabStop (click)="endRowEdit(true)">Apply</button>
1435+
* </ng-template>
1436+
* ```
1437+
*```typescript
1438+
* @ViewChild('template', {read: TemplateRef })
1439+
* public template: TemplateRef<any>;
1440+
* this.grid.rowEditActionsTemplate = this.template;
1441+
* ```
1442+
*/
1443+
public set rowEditActionsTemplate(template: TemplateRef<IgxGridRowEditActionsTemplateContext>) {
1444+
this._rowEditActionsTemplate = template;
1445+
}
13471446

13481447
/**
13491448
* The custom template, if any, that should be used when rendering a row expand indicator.
@@ -2395,24 +2494,6 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
23952494
}
23962495

23972496
/**
2398-
* @hidden @internal
2399-
*/
2400-
public get rowEditText(): TemplateRef<IgxGridRowEditTextTemplateContext> {
2401-
if (this.rowEditTextDirectives && this.rowEditTextDirectives.first) {
2402-
return this.rowEditTextDirectives.first;
2403-
}
2404-
return null;
2405-
}
2406-
2407-
/**
2408-
* @hidden @internal
2409-
*/
2410-
public get rowEditActions(): TemplateRef<IgxGridRowEditActionsTemplateContext> {
2411-
if (this.rowEditActionsDirectives && this.rowEditActionsDirectives.first) {
2412-
return this.rowEditActionsDirectives.first;
2413-
}
2414-
return null;
2415-
}
24162497
24172498
/**
24182499
* @hidden @internal
@@ -2424,10 +2505,24 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
24242505
/**
24252506
* The custom template, if any, that should be used when rendering the row drag indicator icon
24262507
*/
2508+
@Input()
24272509
public get dragIndicatorIconTemplate(): TemplateRef<IgxGridEmptyTemplateContext> {
24282510
return this._customDragIndicatorIconTemplate || this.dragIndicatorIconTemplates.first;
24292511
}
24302512

2513+
/**
2514+
* Sets a custom template that should be used when rendering the row drag indicator icon.
2515+
*```html
2516+
* <ng-template #template igxDragIndicatorIcon>
2517+
* <igx-icon>expand_less</igx-icon>
2518+
* </ng-template>
2519+
* ```
2520+
* ```typescript
2521+
* @ViewChild("'template'", {read: TemplateRef })
2522+
* public template: TemplateRef<any>;
2523+
* this.grid.dragIndicatorIconTemplate = this.template;
2524+
* ```
2525+
*/
24312526
public set dragIndicatorIconTemplate(val: TemplateRef<IgxGridEmptyTemplateContext>) {
24322527
this._customDragIndicatorIconTemplate = val;
24332528
}
@@ -2899,6 +2994,10 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
28992994

29002995
private _customDragIndicatorIconTemplate: TemplateRef<IgxGridEmptyTemplateContext>;
29012996
private _excelStyleHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext>;
2997+
private _rowEditTextTemplate: TemplateRef<IgxGridRowEditTextTemplateContext>;
2998+
private _rowAddTextTemplate: TemplateRef<IgxGridEmptyTemplateContext>;
2999+
private _rowEditActionsTemplate: TemplateRef<IgxGridRowEditActionsTemplateContext>;
3000+
private _dragGhostCustomTemplate: TemplateRef<IgxGridRowDragGhostContext>;
29023001
private _cdrRequests = false;
29033002
private _resourceStrings;
29043003
private _emptyGridMessage = null;
@@ -3789,11 +3888,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
37893888
* @internal
37903889
*/
37913890
public getDragGhostCustomTemplate() {
3792-
if (this.dragGhostCustomTemplates && this.dragGhostCustomTemplates.first) {
3793-
return this.dragGhostCustomTemplates.first;
3794-
}
37953891

3796-
return null;
3892+
return this.dragGhostCustomTemplate;
37973893
}
37983894

37993895
/**

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
IgxGridCustomOverlayComponent,
2323
IgxGridEmptyRowEditTemplateComponent,
2424
VirtualGridComponent,
25-
ObjectCloneStrategy
25+
ObjectCloneStrategy,
26+
IgxGridCustomRowEditTemplateComponent
2627
} from '../../test-utils/grid-samples.spec';
2728
import { Subject } from 'rxjs';
2829
import { takeUntil } from 'rxjs/operators';
@@ -46,6 +47,7 @@ describe('IgxGrid - Row Editing #grid', () => {
4647
IgxGridRowEditingWithoutEditableColumnsComponent,
4748
IgxGridCustomOverlayComponent,
4849
IgxGridEmptyRowEditTemplateComponent,
50+
IgxGridCustomRowEditTemplateComponent,
4951
VirtualGridComponent
5052
],
5153
imports: [
@@ -2127,6 +2129,32 @@ describe('IgxGrid - Row Editing #grid', () => {
21272129
cell = grid.getCellByColumn(0, 'ProductName');
21282130
expect(cell.editMode).toBe(true);
21292131
}));
2132+
2133+
it('should allow setting custom templates via Input.', () => {
2134+
const fix = TestBed.createComponent(IgxGridCustomRowEditTemplateComponent);
2135+
fix.detectChanges();
2136+
const grid = fix.componentInstance.grid;
2137+
2138+
grid.rowAddTextTemplate = fix.componentInstance.addText;
2139+
grid.rowEditTextTemplate = fix.componentInstance.editText;
2140+
grid.rowEditActionsTemplate = fix.componentInstance.editActions;
2141+
fix.detectChanges();
2142+
2143+
// enter edit mode
2144+
const cellElem = grid.gridAPI.get_cell_by_index(0, 'ProductName');
2145+
UIInteractions.simulateDoubleClickAndSelectEvent(cellElem);
2146+
fix.detectChanges();
2147+
2148+
expect(GridFunctions.getRowEditingBannerText(fix)).toBe('CUSTOM EDIT TEXT');
2149+
const bannerRow = GridFunctions.getRowEditingBannerRow(fix);
2150+
expect(bannerRow.textContent.trim()).toBe('CUSTOM EDIT ACTIONS');
2151+
2152+
grid.endEdit();
2153+
2154+
grid.beginAddRowByIndex(0);
2155+
fix.detectChanges();
2156+
expect(GridFunctions.getRowEditingBannerText(fix)).toBe('CUSTOM ADD TEXT');
2157+
});
21302158
});
21312159

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<div class="igx-grid__row-indentation igx-grid__row-indentation--level-{{groupingExpressions.length}}"></div>
125125
</ng-container>
126126
<ng-template
127-
[ngTemplateOutlet]='detailTemplate.first'
127+
[ngTemplateOutlet]='detailTemplate'
128128
[ngTemplateOutletContext]='getDetailsContext(rowData, rowIndex)'>
129129
</ng-template>
130130
</div>
@@ -252,15 +252,15 @@
252252
<div class="igx-banner__message">
253253
<span class="igx-banner__text">
254254
<ng-container
255-
*ngTemplateOutlet="this.crudService.row?.getClassName() === 'IgxAddRow' ? rowAddText : rowEditText ? rowEditText : defaultRowEditText;
255+
*ngTemplateOutlet="this.crudService.row?.getClassName() === 'IgxAddRow' ? rowAddTextTemplate : rowEditTextTemplate ? rowEditTextTemplate : defaultRowEditText;
256256
context: { $implicit: this.crudService.row?.getClassName() !== 'IgxAddRow' ? rowChangesCount : null }">
257257
</ng-container>
258258
</span>
259259
</div>
260260
<div class="igx-banner__actions">
261261
<div class="igx-banner__row">
262262
<ng-container
263-
*ngTemplateOutlet="rowEditActions ? rowEditActions : defaultRowEditActions; context: { $implicit: this.endEdit.bind(this) }">
263+
*ngTemplateOutlet="rowEditActionsTemplate ? rowEditActionsTemplate : defaultRowEditActions; context: { $implicit: this.endEdit.bind(this) }">
264264
</ng-container>
265265
</div>
266266
</div>

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,43 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
154154
/**
155155
* @hidden @internal
156156
*/
157-
@ContentChildren(IgxGridDetailTemplateDirective, { read: TemplateRef })
158-
public detailTemplate: QueryList<TemplateRef<IgxGridMasterDetailContext>> = new QueryList();
157+
@ContentChild(IgxGridDetailTemplateDirective, { read: TemplateRef })
158+
public detailTemplateDirective: TemplateRef<IgxGridMasterDetailContext>;
159+
160+
161+
/**
162+
* Returns a reference to the master-detail template.
163+
* ```typescript
164+
* let detailTemplate = this.grid.detailTemplate;
165+
* ```
166+
*
167+
* @memberof IgxColumnComponent
168+
*/
169+
@Input('detailTemplate')
170+
public get detailTemplate(): TemplateRef<IgxGridMasterDetailContext> {
171+
return this._detailTemplate;
172+
}
173+
/**
174+
* Sets the master-detail template.
175+
* ```html
176+
* <ng-template #detailTemplate igxGridDetail let-dataItem>
177+
* <div>
178+
* <div><span class='categoryStyle'>City:</span> {{dataItem.City}}</div>
179+
* <div><span class='categoryStyle'>Address:</span> {{dataItem.Address}}</div>
180+
* </div>
181+
* </ng-template>
182+
* ```
183+
* ```typescript
184+
* @ViewChild("'detailTemplate'", {read: TemplateRef })
185+
* public detailTemplate: TemplateRef<any>;
186+
* this.grid.detailTemplate = this.detailTemplate;
187+
* ```
188+
*
189+
* @memberof IgxColumnComponent
190+
*/
191+
public set detailTemplate(template: TemplateRef<IgxGridMasterDetailContext>) {
192+
this._detailTemplate = template;
193+
}
159194

160195
/**
161196
* @hidden @internal
@@ -268,6 +303,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
268303
private _hideGroupedColumns = false;
269304
private _dropAreaMessage = null;
270305
private _showGroupArea = true;
306+
private _detailTemplate;
271307

272308
/**
273309
* Gets/Sets the array of data that populates the `IgxGridComponent`.
@@ -562,7 +598,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
562598
* @hidden @internal
563599
*/
564600
public get hasDetails() {
565-
return !!this.detailTemplate.length;
601+
return !!this.detailTemplate;
566602
}
567603

568604
/**
@@ -922,6 +958,10 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
922958
this._groupRowTemplate = this.groupTemplate.template;
923959
}
924960

961+
if (this.detailTemplateDirective) {
962+
this._detailTemplate = this.detailTemplateDirective;
963+
}
964+
925965

926966
if (this.hideGroupedColumns && this._columns && this.groupingExpressions) {
927967
this._setGroupColsVisibility(this.hideGroupedColumns);

0 commit comments

Comments
 (0)