Skip to content

Commit ace6eed

Browse files
authored
Merge pull request #11763 from IgniteUI/mkirova/pivot-chip-templating
Add pivot value chip content template.
2 parents 1f12bd8 + 026bb4f commit ace6eed

File tree

10 files changed

+75
-3
lines changed

10 files changed

+75
-3
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

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

5+
## 14.1.0
6+
7+
- `igxPivotGrid`
8+
- Add option to template the pivot value chip content:
9+
```
10+
<ng-template igxPivotValueChip let-value>
11+
{{ value.member }}
12+
</ng-template>
13+
```
14+
515
## 14.0.0
616
- `IgxDatePicker` and `IgxDateRangePicker` now expose a `weekStart` input property like the `IgxCalendar`
717
- `IgxCombo` and `IgxSimpleComboComponent`

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

+1
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ export interface PivotGridType extends GridType {
652652
hasMultipleValues: boolean;
653653
excelStyleFilterMaxHeight: string;
654654
excelStyleFilterMinHeight: string;
655+
valueChipTemplate: TemplateRef<any>;
655656
}
656657
export interface GridSVGIcon {
657658
name: string;

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
ViewContainerRef,
2424
Injector,
2525
NgModuleRef,
26-
ApplicationRef
26+
ApplicationRef,
27+
ContentChild
2728
} from '@angular/core';
2829
import { IgxGridBaseDirective } from '../grid-base.directive';
2930
import { IgxFilteringService } from '../filtering/grid-filtering.service';
@@ -71,6 +72,7 @@ import { ISortingExpression, SortingDirection } from '../../data-operations/sort
7172
import { DefaultPivotSortingStrategy } from '../../data-operations/pivot-sort-strategy';
7273
import { PivotSortUtil } from './pivot-sort-util';
7374
import { FilterUtil, IFilteringStrategy } from '../../data-operations/filtering-strategy';
75+
import { IgxPivotValueChipTemplateDirective } from './pivot-grid.directives';
7476

7577
let NEXT_ID = 0;
7678
const MINIMUM_COLUMN_WIDTH = 200;
@@ -173,6 +175,23 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
173175
@ViewChild(IgxPivotHeaderRowComponent, { static: true })
174176
public theadRow: IgxPivotHeaderRowComponent;
175177

178+
/**
179+
* @hidden @internal
180+
*/
181+
@ContentChild(IgxPivotValueChipTemplateDirective, { read: IgxPivotValueChipTemplateDirective })
182+
protected valueChipTemplateDirective: IgxPivotValueChipTemplateDirective;
183+
184+
/**
185+
* Gets/Sets a custom template for the value chips.
186+
*
187+
* @example
188+
* ```html
189+
* <igx-pivot-grid [valueChipTemplate]="myTemplate"><igx-pivot-grid>
190+
* ```
191+
*/
192+
@Input()
193+
public valueChipTemplate: TemplateRef<any>;
194+
176195
@Input()
177196
/**
178197
* Gets/Sets the pivot configuration with all related dimensions and values.
@@ -928,6 +947,9 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
928947
Promise.resolve().then(() => {
929948
this.setupColumns();
930949
});
950+
if (this.valueChipTemplateDirective) {
951+
this.valueChipTemplate = this.valueChipTemplateDirective.template;
952+
}
931953
}
932954

933955
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Directive, TemplateRef } from '@angular/core';
2+
/**
3+
* @hidden
4+
*/
5+
@Directive({
6+
selector: '[igxPivotValueChip]'
7+
})
8+
export class IgxPivotValueChipTemplateDirective {
9+
10+
constructor(public template: TemplateRef<any>) { }
11+
12+
}

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IgxPivotRowDimensionContentComponent } from "./pivot-row-dimension-cont
2424
import { IgxPivotRowDimensionHeaderGroupComponent } from "./pivot-row-dimension-header-group.component";
2525
import { IgxPivotRowDimensionHeaderComponent } from "./pivot-row-dimension-header.component";
2626
import { IgxPivotRowComponent } from "./pivot-row.component";
27+
import { IgxPivotValueChipTemplateDirective } from './pivot-grid.directives';
2728

2829
/**
2930
* @hidden
@@ -47,6 +48,7 @@ import { IgxPivotRowComponent } from "./pivot-row.component";
4748
IgxFilterPivotItemsPipe,
4849
IgxPivotGridCellStyleClassesPipe,
4950
IgxPivotDataSelectorComponent,
51+
IgxPivotValueChipTemplateDirective,
5052
],
5153
exports: [
5254
IgxGridModule,
@@ -67,6 +69,7 @@ import { IgxPivotRowComponent } from "./pivot-row.component";
6769
IgxFilterPivotItemsPipe,
6870
IgxPivotGridCellStyleClassesPipe,
6971
IgxPivotDataSelectorComponent,
72+
IgxPivotValueChipTemplateDirective,
7073
],
7174
imports: [IgxGridModule, IgxExpansionPanelModule, IgxDragDropModule, IgxListModule, IgxAccordionModule],
7275
schemas: [CUSTOM_ELEMENTS_SCHEMA]

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

+11
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ describe('IgxPivotGrid #pivotGrid', () => {
108108
expect(pivotGrid.tbody.nativeElement.textContent).toBe('Custom empty template.');
109109
});
110110

111+
it('should allow setting custom chip value template', () => {
112+
const pivotGrid = fixture.componentInstance.pivotGrid as IgxPivotGridComponent;
113+
pivotGrid.valueChipTemplate = fixture.componentInstance.chipValueTemplate;
114+
fixture.detectChanges();
115+
116+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
117+
const valueChip = headerRow.querySelector('igx-chip[id="UnitsSold"]');
118+
let content = valueChip.querySelector('.igx-chip__content');
119+
expect(content.textContent.trim()).toBe('UnitsSold');
120+
});
121+
111122
it('should apply formatter and dataType from measures', () => {
112123
const pivotGrid = fixture.componentInstance.pivotGrid;
113124
pivotGrid.width = '1500px';

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
<igx-icon>functions</igx-icon>
9898
<igx-icon>arrow_drop_down</igx-icon>
9999
</div>
100-
{{value.aggregate.key}}({{value.displayName || value.member}})
100+
<ng-container *ngTemplateOutlet="grid.valueChipTemplate ? grid.valueChipTemplate : valueChipDefaultTemplate; context: { $implicit: value }"></ng-container>
101101
</igx-chip>
102102
<ng-container *ngIf='last'>
103103
<span [style.visibility]='"hidden"' class="igx-grid__tr-pivot--chip_drop_indicator"
@@ -235,3 +235,7 @@
235235
</igx-chip>
236236
</igx-chips-area>
237237
</div>
238+
239+
<ng-template #valueChipDefaultTemplate let-value>
240+
{{value.aggregate.key}}({{value.displayName || value.member}})
241+
</ng-template>

projects/igniteui-angular/src/lib/grids/pivot-grid/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './pivot-row-dimension-content.component';
1010
export * from './pivot-row-dimension-header-group.component';
1111
export * from './pivot-data-selector.component';
1212
export * from './pivot-row-dimension-header.component';
13+
export * from './pivot-grid.directives';

projects/igniteui-angular/src/lib/test-utils/pivot-grid-samples.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ import { IPivotConfiguration, IPivotGridColumn, IPivotGridRecord, PivotAggregati
1818
<ng-template #emptyTemplate>
1919
<span>Custom empty template.</span>
2020
</ng-template>
21+
<ng-template #chipValue let-value>
22+
{{value.member}}
23+
</ng-template>
2124
`
2225
})
2326
export class IgxPivotGridTestBaseComponent {
2427
public defaultExpand = true;
2528
@ViewChild('emptyTemplate', { read: TemplateRef, static: true }) public emptyTemplate: TemplateRef<any>;
29+
@ViewChild('chipValue', { read: TemplateRef, static: true }) public chipValueTemplate: TemplateRef<any>;
2630
@ViewChild('grid', { read: IgxPivotGridComponent, static: true }) public pivotGrid: IgxPivotGridComponent;
2731
@ViewChild('selector', { read: IgxPivotDataSelectorComponent, static: true}) public dataSelector: IgxPivotDataSelectorComponent;
2832
public data;

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@
6767
[rowSelection]='"single"'
6868
[pivotConfiguration]="pivotConfigHierarchy"
6969
(dimensionsChange)="dimensionChange()"
70-
></igx-pivot-grid>
70+
>
71+
<ng-template igxPivotValueChip let-value>
72+
{{ value.member }}
73+
</ng-template>
74+
</igx-pivot-grid>
7175
</div>
7276
<igx-pivot-data-selector [grid]="grid1"></igx-pivot-data-selector>
7377
</div>

0 commit comments

Comments
 (0)