Skip to content

Commit 74f7bce

Browse files
MKirovaMKirova
authored andcommitted
Move row dimension column gen in row.
1 parent 782eabd commit 74f7bce

File tree

6 files changed

+60
-63
lines changed

6 files changed

+60
-63
lines changed

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -172,44 +172,5 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
172172
};
173173
}
174174

175-
public get pivotRows() {
176-
// TODO - resolve member if member is not string.
177-
const rowKeys = this.pivotConfiguration.rows.map(x => x.member);
178-
const cols = this.columns.filter(x => rowKeys.indexOf(x.field) !== -1);
179-
// create copies in order to not pollute the original column.
180-
const columns = [];
181-
const topLevelCols = cols.filter(c => c.level === 0);
182-
topLevelCols.forEach((col) => {
183-
const ref = this._createColumn(col);
184-
ref.changeDetectorRef.detectChanges();
185-
columns.push(ref.instance);
186-
});
187-
return columns;
188-
}
189-
190-
public get pivotRowWidths() {
191-
let width = 0;
192-
this.pivotRows.forEach(col => {
193-
width += col.calcWidth;
194-
});
195-
return width;
196-
}
197-
198-
public get pivotColumns() {
199-
// TODO - resolve member if member is not string.
200-
const rowKeys = this.pivotConfiguration.rows.map(x => x.member);
201-
return this.columns.filter(x => rowKeys.indexOf(x.field) === -1);
202-
}
203-
204-
public get unpinnedColumns(){
205-
const rowKeys = this.pivotConfiguration.rows.map(x => x.member);
206-
const cols = this._unpinnedColumns.filter(x => rowKeys.indexOf(x.field) === -1);
207-
return cols;
208-
}
209175

210-
public get pinnedColumns(){
211-
const rowKeys = this.pivotConfiguration.rows.map(x => x.member);
212-
const cols = this._pinnedColumns.filter(x => rowKeys.indexOf(x.field) === -1);
213-
return cols;
214-
}
215176
}

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
@@ -4,7 +4,7 @@
44
<!-- Column headers area -->
55
<div class="igx-grid__tr" role="row" [style.width.px]="width">
66

7-
<ng-container *ngIf="grid.pivotConfiguration?.rows.length > 0 ">
7+
<ng-container *ngIf="!row">
88
<div #pivotContainer class="igx-grid__tr-action" [style.min-width] = "grid.pivotRowWidths"
99
(pointerdown)="$event.preventDefault()">
1010

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
22
ChangeDetectionStrategy,
3-
Component
3+
Component,
4+
Input
45
} from '@angular/core';
56
import { IgxGridHeaderRowComponent } from '../headers/grid-header-row.component';
7+
import { IgxPivotRowComponent } from './pivot-row.component';
68

79
export interface IgxGridRowSelectorsTemplateContext {
810
$implicit: {
@@ -27,4 +29,6 @@ export interface IgxGridRowSelectorsTemplateContext {
2729
templateUrl: './pivot-header-row.component.html'
2830
})
2931
export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
32+
@Input()
33+
public row: IgxPivotRowComponent;
3034
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<!-- Row Dimension -->
2-
<div #rowDimension>
3-
<!-- TODO: Render headers based on hierarchy here -->
4-
<igx-grid-header-row class="igx-grid-thead" tabindex="0"
2+
<div #rowDimensionContainer>
3+
<igx-pivot-header-row class="igx-grid-thead" tabindex="0"
54
[grid]="grid"
65
[hasMRL]="grid.hasColumnLayouts"
76
[density]="grid.displayDensity"
87
[activeDescendant]="grid.activeDescendant"
9-
[width]="getRowColumnWidth(grid.pivotRows)"
10-
[unpinnedColumnCollection]="getRowColumns(rowData, grid.pivotRows)"
8+
[width]="pivotRowWidths"
9+
[unpinnedColumnCollection]="rowDimension"
1110
(scroll)="grid.preventHeaderScroll($event)"
11+
[row]="this"
1212
>
13-
</igx-grid-header-row>
13+
</igx-pivot-header-row>
1414
</div>
1515

1616

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
import {
22
ChangeDetectionStrategy,
3+
ChangeDetectorRef,
34
Component,
4-
forwardRef
5+
ComponentFactoryResolver,
6+
ElementRef,
7+
forwardRef,
8+
OnInit,
9+
ViewContainerRef
510
} from '@angular/core';
611
import { IgxPivotGridComponent } from './pivot-grid.component';
712
import { IgxRowDirective } from '../row.directive';
8-
import { IgxColumnComponent } from '../hierarchical-grid/public_api';
13+
import { GridBaseAPIService, IgxColumnComponent } from '../hierarchical-grid/public_api';
14+
import { IgxGridSelectionService } from '../selection/selection.service';
915

1016
@Component({
1117
changeDetection: ChangeDetectionStrategy.OnPush,
1218
selector: 'igx-pivot-row',
1319
templateUrl: './pivot-row.component.html',
1420
providers: [{ provide: IgxRowDirective, useExisting: forwardRef(() => IgxPivotRowComponent) }]
1521
})
16-
export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent> {
22+
export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent> implements OnInit {
23+
24+
25+
public rowDimension: IgxColumnComponent[] = [];
26+
27+
constructor(
28+
public gridAPI: GridBaseAPIService<IgxPivotGridComponent>,
29+
public selectionService: IgxGridSelectionService,
30+
public element: ElementRef<HTMLElement>,
31+
public cdr: ChangeDetectorRef,
32+
protected resolver: ComponentFactoryResolver,
33+
protected viewRef: ViewContainerRef
34+
){
35+
super(gridAPI, selectionService, element, cdr);
36+
}
1737

1838
/**
1939
* @hidden
@@ -23,22 +43,34 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
2343
return this.index;
2444
}
2545

26-
public getRowColumns(rowData, cols: IgxColumnComponent[]) {
27-
cols.forEach(col => {
28-
col.header = rowData[col.field];
29-
col.field = rowData[col.field];
30-
col.title = rowData[col.field];
31-
(col as any)._vIndex = this.grid.columns.length + this.index;
32-
});
33-
return cols;
34-
}
35-
36-
public getRowColumnWidth(cols: IgxColumnComponent[]) {
46+
public get pivotRowWidths() {
3747
let width = 0;
38-
cols.forEach(col => {
48+
this.rowDimension.forEach(col => {
3949
width += col.calcWidth;
4050
});
4151
return width;
4252
}
53+
54+
public ngOnInit() {
55+
// generate rowDimension
56+
const rowDimConfig = this.grid.pivotConfiguration.rows;
57+
let field = null;
58+
for (const dim of rowDimConfig) {
59+
if (typeof dim.member === 'string') {
60+
field = this.rowData[dim.member];
61+
} else if (typeof dim.member === 'function'){
62+
field = dim.member.call(this, this.rowData);
63+
}
64+
const col = this._createColComponent(field);
65+
this.rowDimension.push(col);
66+
}
67+
}
68+
69+
protected _createColComponent(field: string) {
70+
const factoryColumn = this.resolver.resolveComponentFactory(IgxColumnComponent);
71+
const ref = this.viewRef.createComponent(factoryColumn, null, this.viewRef.injector);
72+
ref.instance.field = field;
73+
return ref.instance;
74+
}
4375
}
4476

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class PivotGridSampleComponent {
1919
childLevels:[]
2020
}],
2121
rows: [{
22-
member: 'ProductCategory',
22+
member: (data) => data.ProductCategory,
2323
enabled: true,
2424
childLevels:[]
2525
}],

0 commit comments

Comments
 (0)