Skip to content

Commit 872516a

Browse files
MKirovaMKirova
authored andcommitted
Add correct column generation based on column dimensions.
1 parent 74f7bce commit 872516a

File tree

6 files changed

+73
-14
lines changed

6 files changed

+73
-14
lines changed

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

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import { GridType } from '../common/grid.interface';
1717
import { IgxGridNavigationService } from '../grid-navigation.service';
1818
import { IgxGridCRUDService } from '../common/crud.service';
1919
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
20-
import { IPivotConfiguration } from './pivot-grid.interface';
20+
import { IPivotConfiguration, IPivotDimension } from './pivot-grid.interface';
2121
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
2222

2323
let NEXT_ID = 0;
24+
const MINIMUM_COLUMN_WIDTH = 136;
2425
@Component({
2526
changeDetection: ChangeDetectionStrategy.OnPush,
2627
preserveWhitespaces: false,
@@ -72,6 +73,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
7273
private _data;
7374
private _filteredData;
7475
private p_id = `igx-pivot-grid-${NEXT_ID++}`;
76+
private _origData = [];
7577

7678
/**
7779
* @hidden
@@ -83,6 +85,11 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
8385
super.ngOnInit();
8486
}
8587

88+
/** @hidden */
89+
public featureColumnsWidth() {
90+
return this.pivotRowWidths;
91+
}
92+
8693
/**
8794
* Gets/Sets the value of the `id` attribute.
8895
*
@@ -128,9 +135,31 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
128135
* let data = this.grid.data;
129136
* ```
130137
*/
131-
public get data(): any[] | null {
138+
public get data(): any[] | null {
132139
return this._data;
133-
}
140+
}
141+
142+
/**
143+
* Returns an array of data set to the component.
144+
* ```typescript
145+
* let processedData = this.grid.processedData;
146+
* ```
147+
*/
148+
public get originalData(): any[] | null {
149+
return this._origData;
150+
}
151+
152+
153+
/**
154+
* An @Input property that lets you fill the `IgxPivotGridComponent` with an array of data.
155+
* ```html
156+
* <igx-pivot-grid [processedData]="Data"></igx-pivot-grid>
157+
* ```
158+
*/
159+
@Input()
160+
public set originalData(value: any[] | null) {
161+
this._origData = value || [];
162+
}
134163

135164
/**
136165
* Sets an array of objects containing the filtered data.
@@ -172,5 +201,31 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
172201
};
173202
}
174203

204+
public get pivotRowWidths() {
205+
const rowDimCount = this.pivotConfiguration.rows.length;
206+
return MINIMUM_COLUMN_WIDTH * rowDimCount;
207+
}
208+
209+
// TODO: should work on original data, before pipes.
210+
// That should be data, but for this poc since we have no pipes use a different prop.
211+
protected generateDataFields(data: any[]): string[] {
212+
let fields = new Map<string, string>();
213+
for (const rec of this.originalData) {
214+
const vals = this.extractValuesFromDimension(this.pivotConfiguration.columns, rec);
215+
for (const val of vals) {
216+
fields = fields.set(val, val);
217+
}
218+
}
219+
const keys = Array.from(fields.keys());
220+
return keys;
221+
}
175222

223+
private extractValuesFromDimension(dims: IPivotDimension[], recData: any){
224+
const vals = [];
225+
for (const col of dims) {
226+
const value = typeof col.member === 'string' ? recData[col.member] : col.member.call(this, recData);
227+
vals.push(value);
228+
}
229+
return vals;
230+
}
176231
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="igx-grid__tr" role="row" [style.width.px]="width">
66

77
<ng-container *ngIf="!row">
8-
<div #pivotContainer class="igx-grid__tr-action" [style.min-width] = "grid.pivotRowWidths"
8+
<div #pivotContainer class="igx-grid__tr-action" [style.min-width.px] = "grid.pivotRowWidths"
99
(pointerdown)="$event.preventDefault()">
1010

1111
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[hasMRL]="grid.hasColumnLayouts"
66
[density]="grid.displayDensity"
77
[activeDescendant]="grid.activeDescendant"
8-
[width]="pivotRowWidths"
8+
[width]="grid.pivotRowWidths"
99
[unpinnedColumnCollection]="rowDimension"
1010
(scroll)="grid.preventHeaderScroll($event)"
1111
[row]="this"

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { IgxRowDirective } from '../row.directive';
1313
import { GridBaseAPIService, IgxColumnComponent } from '../hierarchical-grid/public_api';
1414
import { IgxGridSelectionService } from '../selection/selection.service';
1515

16+
17+
const MINIMUM_COLUMN_WIDTH = 136;
1618
@Component({
1719
changeDetection: ChangeDetectionStrategy.OnPush,
1820
selector: 'igx-pivot-row',
@@ -43,14 +45,6 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
4345
return this.index;
4446
}
4547

46-
public get pivotRowWidths() {
47-
let width = 0;
48-
this.rowDimension.forEach(col => {
49-
width += col.calcWidth;
50-
});
51-
return width;
52-
}
53-
5448
public ngOnInit() {
5549
// generate rowDimension
5650
const rowDimConfig = this.grid.pivotConfiguration.rows;
@@ -70,6 +64,8 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
7064
const factoryColumn = this.resolver.resolveComponentFactory(IgxColumnComponent);
7165
const ref = this.viewRef.createComponent(factoryColumn, null, this.viewRef.injector);
7266
ref.instance.field = field;
67+
ref.instance.width = MINIMUM_COLUMN_WIDTH + 'px';
68+
(ref as any).instance._vIndex = this.grid.columns.length + this.index;
7369
return ref.instance;
7470
}
7571
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="sample-column">
2-
<igx-pivot-grid #grid1 [data]="data" [pivotConfiguration]="pivotConfig">
2+
<igx-pivot-grid #grid1 [data]="data" [originalData]="origData" [pivotConfiguration]="pivotConfig">
33
</igx-pivot-grid>
44
</div>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ export class PivotGridSampleComponent {
5050
{ ProductCategory: 'Accessories', USA: 293 },
5151
{ ProductCategory: 'Components', USA: 240 }
5252
];
53+
54+
public dataHierarchical = [
55+
{ ProductCategory: 'All', Bulgaria: 774, USA: 829, Uruguay: 524 },
56+
{ ProductCategory: 'Clothing', Bulgaria: 774, USA: 296, Uruguay: 456 },
57+
{ ProductCategory: 'Bikes', Uruguay: 68 },
58+
{ ProductCategory: 'Accessories', USA: 293 },
59+
{ ProductCategory: 'Components', USA: 240 }
60+
];
5361
}

0 commit comments

Comments
 (0)