Skip to content

Commit 4b88bd6

Browse files
authored
Merge branch 'master' into mkirova/expose-rowdrag-template-inputs
2 parents 323d071 + cf50d28 commit 4b88bd6

File tree

6 files changed

+81
-15
lines changed

6 files changed

+81
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes for each version of this project will be documented in this
88
- `igxGrid` - exposing new Input properties:
99
- `dragGhostCustomTemplate` - Gets/Sets the custom template used for row drag.
1010
- `dragIndicatorIconTemplate` - Gets/Sets the custom template used for row drag indicator.
11+
- `detailTemplate` - Gets/Sets the master-detail template.
12+
1113
## 14.2.0
1214

1315
### New Features

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

Lines changed: 1 addition & 1 deletion
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>

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
/**
@@ -921,6 +957,10 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
921957
this._groupRowTemplate = this.groupTemplate.template;
922958
}
923959

960+
if (this.detailTemplateDirective) {
961+
this._detailTemplate = this.detailTemplateDirective;
962+
}
963+
924964

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

projects/igniteui-angular/src/lib/grids/grid/grid.master-detail.spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, OnInit, DebugElement, QueryList } from '@angular/core';
1+
import { Component, ViewChild, OnInit, DebugElement, QueryList, TemplateRef } from '@angular/core';
22
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
33
import { configureTestSuite } from '../../test-utils/configure-suite';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -346,6 +346,17 @@ describe('IgxGrid Master Detail #grid', () => {
346346
expect(row.expanded).toBeFalsy();
347347
});
348348
});
349+
350+
it('should allow setting external details template via Input.', () => {
351+
grid = fix.componentInstance.grid;
352+
grid.detailTemplate = fix.componentInstance.detailTemplate;
353+
fix.detectChanges();
354+
grid.toggleRow(fix.componentInstance.data[0].ID);
355+
fix.detectChanges();
356+
const gridRows = grid.rowList.toArray();
357+
const firstDetail = GridFunctions.getMasterRowDetail(gridRows[0]);
358+
expect(firstDetail.textContent.trim()).toBe('NEW TEMPLATE');
359+
});
349360
});
350361

351362
describe('Keyboard Navigation ', () => {
@@ -1257,12 +1268,20 @@ describe('IgxGrid Master Detail #grid', () => {
12571268
</div>
12581269
</ng-template>
12591270
</igx-grid>
1271+
<ng-template igxGridDetail let-dataItem #detailTemplate>
1272+
<div>
1273+
NEW TEMPLATE
1274+
</div>
1275+
</ng-template>
12601276
`
12611277
})
12621278
export class DefaultGridMasterDetailComponent {
12631279
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
12641280
public grid: IgxGridComponent;
12651281

1282+
@ViewChild('detailTemplate', { read: TemplateRef, static: true })
1283+
public detailTemplate: TemplateRef<any>;
1284+
12661285
public width = '800px';
12671286
public height = '500px';
12681287
public data = SampleTestData.contactInfoDataFull();

src/app/grid-master-detail/grid-master-detail.sample.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
<igx-column-layout field='group1'>
2525
<igx-column [rowStart]="1" [colStart]="1" [rowEnd]="4" field="ID"></igx-column>
2626
</igx-column-layout> -->
27-
<ng-template igxGridDetail let-dataItem>
28-
<div>
29-
<div *ngIf='true'>Test</div>
30-
<div *ngIf="dataItem.Country"><span class='categoryStyle'>Country:</span> {{dataItem.Country}}</div>
31-
<div><span class='categoryStyle'>City:</span> {{dataItem.City}}</div>
32-
<div><span class='categoryStyle'>Address:</span> {{dataItem.Address}}</div>
33-
</div>
34-
</ng-template>
27+
3528
</igx-grid>
3629
<br />
37-
30+
<ng-template igxGridDetail let-dataItem #detailTemplate>
31+
<div>
32+
<div *ngIf='true'>Test</div>
33+
<div *ngIf="dataItem.Country"><span class='categoryStyle'>Country:</span> {{dataItem.Country}}</div>
34+
<div><span class='categoryStyle'>City:</span> {{dataItem.City}}</div>
35+
<div><span class='categoryStyle'>Address:</span> {{dataItem.Address}}</div>
36+
</div>
37+
</ng-template>
3838
<button igxButton="raised" (click)="grid1.expandAll()">Expand All</button>
3939
<button igxButton="raised" (click)="grid1.collapseAll()">Collapse All</button>
4040
<button igxButton="raised" (click)="expandFirstRow()">Expand first</button>

src/app/grid-master-detail/grid-master-detail.sample.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-len */
2-
import { Component, ViewChild, OnInit, Inject } from '@angular/core';
2+
import { Component, ViewChild, OnInit, Inject, TemplateRef } from '@angular/core';
33

44
import { IgxGridComponent, IgxGridStateDirective } from 'igniteui-angular';
55
import { DisplayDensity, IDisplayDensityOptions, DisplayDensityToken } from 'projects/igniteui-angular/src/lib/core/density';
@@ -15,6 +15,9 @@ export class GridMasterDetailSampleComponent implements OnInit {
1515
public data: Array<any>;
1616
public expState = [];
1717
public columns: Array<any>;
18+
@ViewChild('detailTemplate', {read: TemplateRef, static: true })
19+
public detailTemplate: TemplateRef<any>;
20+
1821
constructor(@Inject(DisplayDensityToken) public displayDensityOptions: IDisplayDensityOptions) {}
1922
public ngOnInit(): void {
2023
this.columns = [
@@ -51,6 +54,8 @@ export class GridMasterDetailSampleComponent implements OnInit {
5154
{ Salary: '6600',ID: 'FRANR', CompanyName: 'France restauration', ContactName: 'Carine Schmitt', ContactTitle: 'Marketing Manager', Address: '54, rue Royale', City: 'Nantes', Region: null, PostalCode: '44000', Country: 'France', Phone: '40.32.21.21', Fax: '40.32.21.20' },
5255
{ Salary: '4900',ID: 'FRANS', CompanyName: 'Franchi S.p.A.', ContactName: 'Paolo Accorti', ContactTitle: 'Sales Representative', Address: 'Via Monte Bianco 34', City: 'Torino', Region: null, PostalCode: '10100', Country: 'Italy', Phone: '011-4988260', Fax: '011-4988261' }
5356
];
57+
58+
this.grid1.detailTemplate = this.detailTemplate;
5459
}
5560

5661
public expandFirstRow() {

0 commit comments

Comments
 (0)