Skip to content

Commit 02b0cb2

Browse files
authored
Merge pull request #10508 from IgniteUI/bpachilova/feat-7981-master
feat(grid): add new directive for retemplating summaries
2 parents 13d82c1 + f6804ad commit 02b0cb2

21 files changed

+316
-76
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

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

5+
## 13.0.1
6+
7+
### New Features
8+
- Add `igxSummary` directive in order to re-template the default summary cell layout.
9+
- Expose `summaryTemplate` input in order to bind the column summary template through API.
10+
- Expose `summaryRowHeight` property which overrides the default hight of the summary row.
11+
- Code example below:
12+
13+
```html
14+
<igx-column ... [hasSummary]="true">
15+
<ng-template igxSummary let-summaryResult>
16+
<span> My custom summary template</span>
17+
<span>{{ summaryResult[0].label }} - {{ summaryResult[0].summaryResult }}</span>
18+
</ng-template>
19+
</igx-column>
20+
```
21+
- Please, refer to the [Summaries](https://www.infragistics.com/products/ignite-ui-angular/angular/components/grid/summaries#summary-template) topic for more information.
22+
523
## 13.0.0
624

725
### New Features

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import {
4343
IgxCellHeaderTemplateDirective,
4444
IgxCellEditorTemplateDirective,
4545
IgxCollapsibleIndicatorTemplateDirective,
46-
IgxFilterCellTemplateDirective
46+
IgxFilterCellTemplateDirective,
47+
IgxSummaryTemplateDirective
4748
} from './templates.directive';
4849
import { MRLResizeColumnInfo, MRLColumnSizeInfo, IColumnPipeArgs } from './interfaces';
4950
import { DropPosition } from '../moving/moving.service';
@@ -833,6 +834,11 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
833834
*/
834835
@ContentChild(IgxFilterCellTemplateDirective, { read: IgxFilterCellTemplateDirective })
835836
public filterCellTemplateDirective: IgxFilterCellTemplateDirective;
837+
/**
838+
* @hidden
839+
*/
840+
@ContentChild(IgxSummaryTemplateDirective, { read: IgxSummaryTemplateDirective })
841+
protected summaryTemplateDirective: IgxSummaryTemplateDirective;
836842
/**
837843
* @hidden
838844
*/
@@ -853,7 +859,6 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
853859
*/
854860
@ContentChild(IgxCollapsibleIndicatorTemplateDirective, { read: IgxCollapsibleIndicatorTemplateDirective, static: false })
855861
protected collapseIndicatorTemplate: IgxCollapsibleIndicatorTemplateDirective;
856-
857862
/**
858863
* @hidden
859864
*/
@@ -1109,6 +1114,39 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
11091114
return '80';
11101115
}
11111116
}
1117+
/**
1118+
* Returns a reference to the `summaryTemplate`.
1119+
* ```typescript
1120+
* let summaryTemplate = this.column.summaryTemplate;
1121+
* ```
1122+
*
1123+
* @memberof IgxColumnComponent
1124+
*/
1125+
@notifyChanges()
1126+
@WatchColumnChanges()
1127+
@Input()
1128+
public get summaryTemplate(): TemplateRef<any> {
1129+
return this._summaryTemplate;
1130+
}
1131+
/**
1132+
* Sets the summary template.
1133+
* ```html
1134+
* <ng-template #summaryTemplate igxSummary let-summaryResults>
1135+
* <p>{{ summaryResults[0].label }}: {{ summaryResults[0].summaryResult }}</p>
1136+
* <p>{{ summaryResults[1].label }}: {{ summaryResults[1].summaryResult }}</p>
1137+
* </ng-template>
1138+
* ```
1139+
* ```typescript
1140+
* @ViewChild("'summaryTemplate'", {read: TemplateRef })
1141+
* public summaryTemplate: TemplateRef<any>;
1142+
* this.column.summaryTemplate = this.summaryTemplate;
1143+
* ```
1144+
*
1145+
* @memberof IgxColumnComponent
1146+
*/
1147+
public set summaryTemplate(template: TemplateRef<any>) {
1148+
this._summaryTemplate = template;
1149+
}
11121150
/**
11131151
* Returns a reference to the `bodyTemplate`.
11141152
* ```typescript
@@ -1565,6 +1603,10 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
15651603
* @hidden
15661604
*/
15671605
protected _headerTemplate: TemplateRef<any>;
1606+
/**
1607+
* @hidden
1608+
*/
1609+
protected _summaryTemplate: TemplateRef<any>;
15681610
/**
15691611
* @hidden
15701612
*/
@@ -1672,6 +1714,9 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
16721714
* @hidden
16731715
*/
16741716
public ngAfterContentInit(): void {
1717+
if (this.summaryTemplateDirective) {
1718+
this._summaryTemplate = this.summaryTemplateDirective.template;
1719+
}
16751720
if (this.cellTemplate) {
16761721
this._bodyTemplate = this.cellTemplate.template;
16771722
}

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+
IgxSummaryTemplateDirective
1213
} from './templates.directive';
1314

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

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

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

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

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export interface ColumnType {
157157
filteringExpressionsTree: FilteringExpressionsTree;
158158
hasSummary: boolean;
159159
summaries: any;
160+
summaryTemplate: TemplateRef<any>;
160161
pinned: boolean;
161162
expanded: boolean;
162163
selected: boolean;
@@ -372,6 +373,7 @@ export interface GridType extends IGridDataBindable {
372373
dataWithAddedInTransactionRows: any[];
373374
transactions: TransactionService<Transaction, State>;
374375
defaultSummaryHeight: number;
376+
summaryRowHeight: number;
375377
rowEditingOverlay: IgxToggleDirective;
376378
totalRowsCountAfterFilter: number;
377379
_totalRecords: number;

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,25 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
221221
@Input()
222222
public loadingGridTemplate: TemplateRef<any>;
223223

224+
/**
225+
* Get/Set IgxSummaryRow height
226+
*/
227+
@Input()
228+
public set summaryRowHeight(value: number) {
229+
this._summaryRowHeight = value | 0;
230+
this.summaryService.summaryHeight = value;
231+
if (!this._init) {
232+
this.reflow();
233+
}
234+
}
235+
236+
public get summaryRowHeight(): number {
237+
if (this.hasSummarizedColumns && this.rootSummariesEnabled) {
238+
return this._summaryRowHeight || this.summaryService.calcMaxSummaryHeight();
239+
}
240+
return 0;
241+
}
242+
224243
/**
225244
* Controls the copy behavior of the grid.
226245
*/
@@ -2510,10 +2529,6 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
25102529
* @hidden @internal
25112530
*/
25122531
public tfootHeight: number;
2513-
/**
2514-
* @hidden @internal
2515-
*/
2516-
public summariesHeight: number;
25172532

25182533
/**
25192534
* @hidden @internal
@@ -2752,6 +2767,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
27522767
private _summaryPosition: GridSummaryPosition = GridSummaryPosition.bottom;
27532768
private _summaryCalculationMode: GridSummaryCalculationMode = GridSummaryCalculationMode.rootAndChildLevels;
27542769
private _showSummaryOnCollapse = false;
2770+
private _summaryRowHeight = 0;
27552771
private _cellSelectionMode: GridSelectionMode = GridSelectionMode.multiple;
27562772
private _rowSelectionMode: GridSelectionMode = GridSelectionMode.none;
27572773
private _selectRowOnClick = true;
@@ -3220,7 +3236,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
32203236

32213237
this.onDensityChanged.pipe(destructor).subscribe(() => {
32223238
this.crudService.endEdit(false);
3239+
if (this._summaryRowHeight === 0) {
32233240
this.summaryService.summaryHeight = 0;
3241+
}
32243242
this.notifyChanges(true);
32253243
});
32263244
}
@@ -6321,10 +6339,6 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
63216339
*/
63226340
protected calculateGridHeight() {
63236341
this.calcGridHeadRow();
6324-
this.summariesHeight = 0;
6325-
if (this.hasSummarizedColumns && this.rootSummariesEnabled) {
6326-
this.summariesHeight = this.summaryService.calcMaxSummaryHeight();
6327-
}
63286342

63296343
this.calcHeight = this._calculateGridBodyHeight();
63306344
if (this.pinnedRowHeight && this.calcHeight) {
@@ -6349,7 +6363,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
63496363
* @hidden
63506364
*/
63516365
protected getFooterHeight(): number {
6352-
return this.summariesHeight || this.getComputedHeight(this.tfoot.nativeElement);
6366+
return this.summaryRowHeight || this.getComputedHeight(this.tfoot.nativeElement);
63536367
}
63546368
/**
63556369
* @hidden

0 commit comments

Comments
 (0)