Skip to content

Commit 6b601cb

Browse files
author
ddaribo
committed
feat(grid): add new directive for retemplating summaries
1 parent 400ba57 commit 6b601cb

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import {
4545
IgxCellHeaderTemplateDirective,
4646
IgxCellEditorTemplateDirective,
4747
IgxCollapsibleIndicatorTemplateDirective,
48-
IgxFilterCellTemplateDirective
48+
IgxFilterCellTemplateDirective,
49+
IgxCustomSummaryCellTemplateDirective
4950
} from './templates.directive';
5051
import { MRLResizeColumnInfo, MRLColumnSizeInfo, IColumnPipeArgs } from './interfaces';
5152
import { DropPosition } from '../moving/moving.service';
@@ -837,6 +838,11 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
837838
*/
838839
@ContentChild(IgxFilterCellTemplateDirective, { read: IgxFilterCellTemplateDirective })
839840
public filterCellTemplateDirective: IgxFilterCellTemplateDirective;
841+
/**
842+
* @hidden
843+
*/
844+
@ContentChild(IgxCustomSummaryCellTemplateDirective, { read: IgxCustomSummaryCellTemplateDirective })
845+
public customSummaryCellTemplateDirective: IgxCustomSummaryCellTemplateDirective;
840846
/**
841847
* @hidden
842848
*/
@@ -857,7 +863,6 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
857863
*/
858864
@ContentChild(IgxCollapsibleIndicatorTemplateDirective, { read: IgxCollapsibleIndicatorTemplateDirective, static: false })
859865
protected collapseIndicatorTemplate: IgxCollapsibleIndicatorTemplateDirective;
860-
861866
/**
862867
* @hidden
863868
*/
@@ -1257,7 +1262,36 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
12571262
public set filterCellTemplate(template: TemplateRef<any>) {
12581263
this._filterCellTemplate = template;
12591264
}
1260-
1265+
/**
1266+
* Returns a reference to the `customSummaryCellTemplate`.
1267+
* ```typescript
1268+
* let customSummaryCellTemplate = this.column.customSummaryCellTemplate;
1269+
* ```
1270+
*
1271+
* @memberof IgxColumnComponent
1272+
*/
1273+
@notifyChanges()
1274+
@WatchColumnChanges()
1275+
@Input()
1276+
public get customSummaryCellTemplate(): TemplateRef<any> {
1277+
return this._customSummaryCellTemplate;
1278+
}
1279+
/**
1280+
* Sets the custom summary cell template.
1281+
* ```html
1282+
* <ng-template igxCustomSummaryCell let-summaryResults>
1283+
* {{ summaryResults[0].label }}
1284+
* </ng-template>
1285+
* ```
1286+
* ```typescript
1287+
*
1288+
* ```
1289+
*
1290+
* @memberof IgxColumnComponent
1291+
*/
1292+
public set customSummaryCellTemplate(template: TemplateRef<any>) {
1293+
this._customSummaryCellTemplate = template;
1294+
}
12611295
/**
12621296
* Gets the cells of the column.
12631297
* ```typescript
@@ -1588,6 +1622,10 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
15881622
* @hidden
15891623
*/
15901624
protected _filterCellTemplate: TemplateRef<any>;
1625+
/**
1626+
* @hidden
1627+
*/
1628+
protected _customSummaryCellTemplate: TemplateRef<any>;
15911629
/**
15921630
* @hidden
15931631
*/
@@ -1699,6 +1737,9 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
16991737
if (this.filterCellTemplateDirective) {
17001738
this._filterCellTemplate = this.filterCellTemplateDirective.template;
17011739
}
1740+
if (this.customSummaryCellTemplateDirective) {
1741+
this._customSummaryCellTemplate = this.customSummaryCellTemplateDirective.template;
1742+
}
17021743
if (!this._columnPipeArgs.format) {
17031744
this._columnPipeArgs.format = this.dataType === GridColumnDataType.Time ?
17041745
DEFAULT_TIME_FORMAT : this.dataType === GridColumnDataType.DateTime ?

projects/igniteui-angular/src/lib/grids/columns/column.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import {
88
IgxCellHeaderTemplateDirective,
99
IgxCellTemplateDirective,
1010
IgxCollapsibleIndicatorTemplateDirective,
11-
IgxFilterCellTemplateDirective
11+
IgxFilterCellTemplateDirective,
12+
IgxCustomSummaryCellTemplateDirective
1213
} from './templates.directive';
1314

14-
1515
@NgModule({
1616
declarations: [
1717
IgxFilterCellTemplateDirective,
18+
IgxCustomSummaryCellTemplateDirective,
1819
IgxCellTemplateDirective,
1920
IgxCellHeaderTemplateDirective,
2021
IgxCellFooterTemplateDirective,
@@ -31,6 +32,7 @@ import {
3132
],
3233
exports: [
3334
IgxFilterCellTemplateDirective,
35+
IgxCustomSummaryCellTemplateDirective,
3436
IgxCellTemplateDirective,
3537
IgxCellHeaderTemplateDirective,
3638
IgxCellFooterTemplateDirective,

projects/igniteui-angular/src/lib/grids/columns/templates.directive.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ export class IgxCollapsibleIndicatorTemplateDirective {
5050

5151
constructor(public template: TemplateRef<any>) { }
5252
}
53+
54+
@Directive({
55+
selector: '[igxCustomSummaryCell]'
56+
})
57+
export class IgxCustomSummaryCellTemplateDirective {
58+
constructor(public template: TemplateRef<any>) { }
59+
}

projects/igniteui-angular/src/lib/grids/summaries/summary-cell.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<ng-container *ngIf="hasSummary">
2-
<ng-container *ngFor="let summary of summaryResults">
2+
<ng-container
3+
*ngTemplateOutlet="column.customSummaryCellTemplate ? column.customSummaryCellTemplate : defaultSummary; context: { $implicit: summaryResults, summaryResults: summaryResults}">
4+
</ng-container>
5+
6+
<ng-template #defaultSummary>
7+
<ng-container *ngFor="let summary of summaryResults" >
38
<div class="igx-grid-summary__item" [style.height.px]="itemHeight">
49

510
<ng-container *ngIf="visibleColumnIndex === 0 && firstCellIndentation >= 0">
@@ -29,5 +34,6 @@
2934
}}
3035
</span>
3136
</div>
32-
</ng-container>
37+
</ng-container>
38+
</ng-template>
3339
</ng-container>

src/app/grid-summaries/grid-summaries.sample.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<ng-template igxCell let-cell="cell" let-val let-row>
3131
${{val}}
3232
</ng-template>
33+
<ng-template igxCustomSummaryCell let-summaryResults>
34+
<span>Custom summary cell:</span>
35+
<span>Number of Summaries: {{ summaryResults.length }}</span>
36+
<span>FirstSummary - {{ summaryResults[0].label }}: {{ summaryResults[0].summaryResult }}</span>
37+
</ng-template>
3338
</igx-column>
3439
<igx-column field="OrderDate" [width]="cw" [dataType]="'date'" [hasSummary]="false" [sortable]="true">
3540
</igx-column>

0 commit comments

Comments
 (0)