Skip to content

Commit 82a3c74

Browse files
authored
Merge pull request #10182 from IgniteUI/dkamburov/pivot-pipes
pivot pipes
2 parents d8f3fa1 + e264a3f commit 82a3c74

File tree

13 files changed

+757
-105
lines changed

13 files changed

+757
-105
lines changed

projects/igniteui-angular/karma.azure.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function (config) {
1919
require('@angular-devkit/build-angular/plugins/karma')
2020
],
2121
parallelOptions: {
22-
executors: 2,
22+
executors: 3,
2323
shardStrategy: 'round-robin'
2424
},
2525
client: {

projects/igniteui-angular/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function (config) {
2222
require('@angular-devkit/build-angular/plugins/karma')
2323
],
2424
parallelOptions: {
25-
executors: 2,
25+
executors: 3,
2626
shardStrategy: 'round-robin'
2727
},
2828
client: {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
[igxColumnMovingDrop]="headerContainer" [attr.droppable]="true" id="left"
3232
class="igx-grid__scroll-on-drag-pinned" [style.left.px]="pinnedWidth"></span>
3333
<ng-template igxGridFor let-rowData [igxGridForOf]="data
34-
| gridPivotFilter:pivotConfiguration.filters:filterStrategy:advancedFilteringExpressionsTree
35-
| gridPivotRow:pivotConfiguration.rows:pivotConfiguration.values"
34+
| pivotGridFilter:pivotConfiguration.filters:filterStrategy:advancedFilteringExpressionsTree
35+
| pivotGridRow:pivotConfiguration.rows:expansionStates:pivotConfiguration.values
36+
| pivotGridColumn:pivotConfiguration.columns:pivotConfiguration.values"
3637
let-rowIndex="index" [igxForScrollOrientation]="'vertical'" [igxForScrollContainer]='verticalScroll'
3738
[igxForContainerSize]='calcHeight'
3839
[igxForItemSize]="hasColumnLayouts ? rowHeight * multiRowLayoutRowSize + 1 : renderedRowHeight"
@@ -116,7 +117,7 @@
116117
<igx-icon [attr.draggable]="false"
117118
(click)="toggleColumn(column)"
118119
style='cursor: pointer;'>
119-
{{columnGroupStates.get(column) ? 'expand_more' : 'expand_less'}}</igx-icon>
120+
{{columnGroupStates.get(column.field) ? 'expand_more' : 'expand_less'}}</igx-icon>
120121
{{column.header}}
121122
</div>
122123
</ng-template>

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

Lines changed: 63 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IPivotConfiguration, IPivotDimension } from './pivot-grid.interface';
2121
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
2222
import { IgxColumnGroupComponent } from '../columns/column-group.component';
2323
import { IgxColumnComponent } from '../columns/column.component';
24+
import { PivotUtil } from './pivot-util';
2425

2526
let NEXT_ID = 0;
2627
const MINIMUM_COLUMN_WIDTH = 200;
@@ -80,12 +81,12 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
8081
public headerTemplate: TemplateRef<any>;
8182

8283

83-
public columnGroupStates = new Map<IgxColumnGroupComponent, boolean>();
84+
public columnGroupStates = new Map<string, boolean>();
8485
public isPivot = true;
86+
protected _defaultExpandState = true;
8587
private _data;
8688
private _filteredData;
8789
private p_id = `igx-pivot-grid-${NEXT_ID++}`;
88-
private _origData = [];
8990

9091
/**
9192
* @hidden
@@ -150,29 +151,6 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
150151
public get data(): any[] | null {
151152
return this._data;
152153
}
153-
154-
/**
155-
* Returns an array of data set to the component.
156-
* ```typescript
157-
* let processedData = this.grid.processedData;
158-
* ```
159-
*/
160-
public get originalData(): any[] | null {
161-
return this._origData;
162-
}
163-
164-
165-
/**
166-
* An @Input property that lets you fill the `IgxPivotGridComponent` with an array of data.
167-
* ```html
168-
* <igx-pivot-grid [processedData]="Data"></igx-pivot-grid>
169-
* ```
170-
*/
171-
@Input()
172-
public set originalData(value: any[] | null) {
173-
this._origData = value || [];
174-
}
175-
176154
/**
177155
* Sets an array of objects containing the filtered data.
178156
* ```typescript
@@ -219,16 +197,54 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
219197
}
220198

221199
public toggleColumn(col: IgxColumnComponent) {
222-
const state = this.columnGroupStates.get(col);
223-
this.columnGroupStates.set(col, !state);
200+
const state = this.columnGroupStates.get(col.field);
201+
const newState = !state;
202+
this.columnGroupStates.set(col.field, newState);
203+
const parentCols = col.parent ? col.parent.children : this.columns.filter(x => x.level === 0);
204+
const fieldColumn = parentCols.filter(x => x.header === col.header && !x.columnGroup)[0];
205+
const groupColumn = parentCols.filter(x => x.header === col.header && x.columnGroup)[0];
206+
groupColumn.hidden = newState;
207+
this.resolveToggle(groupColumn);
208+
fieldColumn.hidden = !newState;
209+
if (newState) {
210+
fieldColumn.headerTemplate = this.headerTemplate;
211+
} else {
212+
fieldColumn.headerTemplate = undefined;
213+
}
214+
this.reflow();
215+
}
216+
217+
protected resolveToggle(groupColumn: IgxColumnComponent) {
218+
const hasChildGroup = groupColumn.children.filter(x => x.columnGroup).length > 0;
219+
if (!groupColumn.hidden && hasChildGroup) {
220+
const fieldChildren = groupColumn.children.filter(x => !x.columnGroup);
221+
const groupChildren = groupColumn.children.filter(x => x.columnGroup);
222+
groupChildren.forEach(group => {
223+
this.resolveToggle(group);
224+
});
225+
fieldChildren.forEach(fieldChild => {
226+
fieldChild.hidden = true;
227+
});
228+
}
224229
}
225230

231+
/**
232+
* @hidden
233+
* @internal
234+
*/
235+
protected calcGridHeadRow() {
236+
}
237+
226238
/**
227239
* @hidden
228240
*/
229241
protected autogenerateColumns() {
230242
const data = this.gridAPI.get_data();
231-
const fieldsMap = this.getFieldsHierarchy(data);
243+
const fieldsMap = PivotUtil.getFieldsHierarchy(
244+
data,
245+
this.pivotConfiguration.columns,
246+
{aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'}
247+
);
232248
const columns = this.generateColumnHierarchy(fieldsMap, data);
233249
this._autoGeneratedCols = columns;
234250

@@ -243,61 +259,41 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
243259
const factoryColumnGroup = this.resolver.resolveComponentFactory(IgxColumnGroupComponent);
244260
let columns = [];
245261
fields.forEach((value, key) => {
246-
if (value.children == null || value.children.size === 0) {
262+
if (value.children == null || value.children.length === 0 || value.children.size === 0) {
247263
const ref = factoryColumn.create(this.viewRef.injector);
248-
ref.instance.header = key;
264+
ref.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
249265
ref.instance.field = key;
250266
ref.instance.dataType = this.resolveDataTypes(data[0][key]);
251267
ref.instance.parent = parent;
252268
ref.changeDetectorRef.detectChanges();
253269
columns.push(ref.instance);
254270
} else {
255271
const ref = factoryColumnGroup.create(this.viewRef.injector);
256-
ref.instance.header = key;
257-
ref.instance.headerTemplate = this.headerTemplate;
272+
ref.instance.parent = parent;
273+
ref.instance.field = key;
274+
ref.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
275+
if (value.expandable) {
276+
ref.instance.headerTemplate = this.headerTemplate;
277+
const refSibling = factoryColumn.create(this.viewRef.injector);
278+
refSibling.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
279+
refSibling.instance.field = key;
280+
refSibling.instance.dataType = this.resolveDataTypes(data[0][key]);
281+
refSibling.instance.parent = parent;
282+
refSibling.instance.hidden = true;
283+
columns.push(refSibling.instance);
284+
}
258285
const children = this.generateColumnHierarchy(value.children, data, ref.instance);
286+
const filteredChildren = children.filter(x => x.level === ref.instance.level + 1);
259287
ref.changeDetectorRef.detectChanges();
260-
ref.instance.children.reset(children);
288+
289+
ref.instance.children.reset(filteredChildren);
290+
261291
columns.push(ref.instance);
262292
columns = columns.concat(children);
263293
}
264294
});
265295
return columns;
266296
}
267297

268-
protected getFieldsHierarchy(data){
269-
const hierarchy = new Map<string, any>();
270-
for (const rec of this.originalData) {
271-
const vals = this.extractValuesFromDimension(this.pivotConfiguration.columns, rec);
272-
for (const val of vals) {
273-
if (hierarchy.get(val.value) != null && val.children) {
274-
for (const child of val.children) {
275-
hierarchy.get(val.value).children.set(child.value, child);
276-
}
277-
} else {
278-
hierarchy.set(val.value, val);
279-
hierarchy.get(val.value).children = new Map<string, any>();
280-
for (const child of val.children) {
281-
hierarchy.get(val.value).children.set(child.value, child);
282-
}
283-
}
284-
}
285-
}
286-
return hierarchy;
287-
}
288298

289-
private extractValuesFromDimension(dims: IPivotDimension[], recData: any){
290-
const vals = [];
291-
let i = 0;
292-
for (const col of dims) {
293-
const value = typeof col.member === 'string' ? recData[col.member] : col.member.call(this, recData);
294-
vals.push({ value });
295-
if (col.childLevels != null && col.childLevels.length > 0) {
296-
const childValues = this.extractValuesFromDimension(col.childLevels, recData);
297-
vals[i].children = childValues;
298-
}
299-
i++;
300-
}
301-
return vals;
302-
}
303299
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface IPivotDimension {
1515
member: string | ((data: any) => any);
1616
// Enables/Disables a particular dimension from pivot structure.
1717
enabled: boolean;
18+
// additional field name when using member as a function
19+
fieldName?: string;
1820
}
1921

2022
export interface IPivotValue {
@@ -24,3 +26,10 @@ export interface IPivotValue {
2426
// Enables/Disables a particular value from pivot aggregation.
2527
enabled: boolean;
2628
}
29+
30+
export interface IPivotKeys {
31+
children: string;
32+
records: string;
33+
aggregations: string;
34+
level: string;
35+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
2222
IgxGridModule,
2323
IgxPivotGridComponent,
2424
IgxPivotRowComponent,
25-
IgxPivotHeaderRowComponent
25+
IgxPivotHeaderRowComponent,
26+
IgxPivotRowPipe,
27+
IgxPivotColumnPipe,
28+
IgxPivotGridFilterPipe
2629
],
2730
imports: [
2831
IgxGridModule,

0 commit comments

Comments
 (0)