Skip to content

Commit ca10fbe

Browse files
authored
Merge pull request #10503 from IgniteUI/mkirova/small-ui-changes
Add indentation based on level and set correct collapsed state icon as per the design
2 parents 7aecb7a + 3e7a8cf commit ca10fbe

File tree

8 files changed

+70
-26
lines changed

8 files changed

+70
-26
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ export interface PivotGridType extends GridType {
628628
setupColumns(): void;
629629
toggleRow(rowID: any): void;
630630
resolveDataTypes(field: any): GridColumnDataType;
631+
resolveRowDimensionWidth(dim: IPivotDimension): number;
631632
dimensionsChange: EventEmitter<IDimensionsChange>;
632633
valuesChange: EventEmitter<IValuesChange>;
633634
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
</ng-template>
4848
</ng-template>
4949
<ng-template #record_template let-rowIndex="index" let-rowData>
50-
<igx-pivot-row [gridID]="id" [index]="rowIndex" [data]="rowData" [ngClass]="rowClasses | igxGridRowClasses:row:row.inEditMode:row.selected:row.dirty:row.deleted:row.dragging:rowIndex:hasColumnLayouts:false:pipeTrigger"
50+
<igx-pivot-row [pivotRowWidths]='pivotRowWidths' [gridID]="id" [index]="rowIndex" [data]="rowData"
51+
[ngClass]="rowClasses | igxGridRowClasses:row:row.inEditMode:row.selected:row.dirty:row.deleted:row.dragging:rowIndex:hasColumnLayouts:false:pipeTrigger"
5152
[ngStyle]="rowStyles | igxGridRowStyles:rowData:rowIndex:pipeTrigger" #row>
5253
</igx-pivot-row>
5354
</ng-template>

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,19 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
661661
}
662662

663663
public get pivotRowWidths() {
664-
const rowDimCount = this.rowDimensions.length;
665-
return MINIMUM_COLUMN_WIDTH * rowDimCount || MINIMUM_COLUMN_WIDTH;
664+
return this.rowDimensions.reduce((accumulator, dim) => accumulator + this.resolveRowDimensionWidth(dim), 0);
665+
}
666+
667+
public resolveRowDimensionWidth(dim: IPivotDimension): number {
668+
if(!dim.width) {
669+
return MINIMUM_COLUMN_WIDTH;
670+
}
671+
const isPercent = dim.width && dim.width.indexOf('%') !== -1;
672+
if (isPercent) {
673+
return parseFloat(dim.width) / 100 * this.calcWidth;
674+
} else {
675+
return parseInt(dim.width, 10);
676+
}
666677
}
667678

668679
public get rowDimensions() {
@@ -1063,13 +1074,14 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10631074
ref.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
10641075
ref.instance.field = key;
10651076
ref.instance.parent = parent;
1077+
ref.instance.width = value.dimension.width || MINIMUM_COLUMN_WIDTH + 'px';
10661078
ref.instance.dataType = this.pivotConfiguration.values[0]?.dataType || this.resolveDataTypes(data[0][key]);
10671079
ref.instance.formatter = this.pivotConfiguration.values[0]?.formatter;
10681080
ref.instance.sortable = true;
10691081
ref.changeDetectorRef.detectChanges();
10701082
columns.push(ref.instance);
10711083
if (this.hasMultipleValues) {
1072-
const measureChildren = this.getMeasureChildren(factoryColumn, data, ref.instance, false);
1084+
const measureChildren = this.getMeasureChildren(factoryColumn, data, ref.instance, false, value.dimension.width);
10731085
ref.instance.children.reset(measureChildren);
10741086
columns = columns.concat(measureChildren);
10751087
}
@@ -1088,6 +1100,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10881100
refSibling.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
10891101
refSibling.instance.field = key;
10901102
refSibling.instance.parent = parent;
1103+
ref.instance.width = value.dimension.width || MINIMUM_COLUMN_WIDTH + 'px';
10911104
ref.instance.sortable = true;
10921105
refSibling.instance.hidden = true;
10931106
refSibling.instance.dataType = this.pivotConfiguration.values[0]?.dataType || this.resolveDataTypes(data[0][key]);
@@ -1099,7 +1112,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10991112
ref.changeDetectorRef.detectChanges();
11001113
columns.push(ref.instance);
11011114
if (this.hasMultipleValues) {
1102-
const measureChildren = this.getMeasureChildren(factoryColumn, data, ref.instance, true);
1115+
const measureChildren = this.getMeasureChildren(factoryColumn, data, ref.instance, true, value.dimension.width);
11031116
const nestedChildren = filteredChildren.concat(measureChildren);
11041117
const allChildren = children.concat(measureChildren);
11051118
ref.instance.children.reset(nestedChildren);
@@ -1114,13 +1127,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11141127
return columns;
11151128
}
11161129

1117-
protected getMeasureChildren(colFactory, data, parent, hidden) {
1130+
protected getMeasureChildren(colFactory, data, parent, hidden, parentWidth) {
11181131
const cols = [];
1132+
const count = this.values.length;
1133+
const width = parentWidth ? parseInt(parentWidth, 10) / count : MINIMUM_COLUMN_WIDTH;
1134+
const isPercent = parentWidth && parentWidth.indexOf('%') !== -1;
11191135
this.values.forEach(val => {
11201136
const ref = colFactory.create(this.viewRef.injector);
11211137
ref.instance.header = val.displayName || val.member;
11221138
ref.instance.field = parent.field + '-' + val.member;
11231139
ref.instance.parent = parent;
1140+
ref.instance.width = isPercent ? width + '%' : width + 'px';
11241141
ref.instance.hidden = hidden;
11251142
ref.instance.sortable = true;
11261143
ref.instance.dataType = val.dataType || this.resolveDataTypes(data[0][val.member]);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export interface IPivotDimension {
6666
filter?: FilteringExpressionsTree | null;
6767
sortDirection?: SortingDirection;
6868
dataType?: GridColumnDataType;
69+
// The width of the dimension cells to be rendered.Can be pixel or %.
70+
width? : string;
6971
}
7072

7173
export interface IPivotValue {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
2828
}));
2929

3030
it('should apply formatter and dataType from measures', () => {
31-
fixture.detectChanges();
3231
const pivotGrid = fixture.componentInstance.pivotGrid;
32+
pivotGrid.width = '1500px';
33+
fixture.detectChanges();
34+
3335
const actualFormatterValue = pivotGrid.rowList.first.cells.first.title;
3436
expect(actualFormatterValue).toEqual('774$');
3537
const actualDataTypeValue = pivotGrid.rowList.first.cells.last.title;
@@ -330,8 +332,9 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
330332
});
331333

332334
it('should allow changing default aggregation via value chip drop-down.', () => {
333-
fixture.detectChanges();
334335
const pivotGrid = fixture.componentInstance.pivotGrid;
336+
pivotGrid.width = '1500px';
337+
fixture.detectChanges();
335338
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
336339
const valueChip = headerRow.querySelector('igx-chip[id="UnitsSold"]');
337340
let content = valueChip.querySelector('.igx-chip__content');

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,18 @@
9898

9999

100100
<ng-template #headerTemplate let-column>
101-
<div class="igx-grid__tr--header">
102-
<igx-icon [attr.draggable]="false" (click)="grid.toggleRow(getRowDimensionKey(column))">
103-
{{ getExpandState(column) ? 'expand_more' : 'expand_less'}}</igx-icon>
101+
<div class='igx-grid__tr--header igx-grid__row-indentation--level-{{getLevel(column)}}'>
102+
<igx-icon [attr.draggable]="false"
103+
(click)="grid.toggleRow(getRowDimensionKey(column))">
104+
{{ getExpandState(column) ? 'expand_more' : 'chevron_right'}}</igx-icon>
104105
{{column.header}}
105106
</div>
106107
</ng-template>
107108

108-
<ng-template #headerTemplateGray let-column>
109-
<div class="igx-grid__tr--header">
109+
<ng-template #headerDefaultTemplate let-column>
110+
111+
<div class='igx-grid__tr--header igx-grid__row-indentation--level-{{getLevel(column)}}'>
112+
<igx-icon style='flex-shrink: 0;' [attr.draggable]="false"></igx-icon>
110113
{{column.header}}
111114
</div>
112115
</ng-template>

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
SimpleChanges,
1111
TemplateRef,
1212
ViewChild,
13-
ViewContainerRef
13+
ViewContainerRef,
14+
Input
1415
} from '@angular/core';
1516
import { IgxRowDirective } from '../row.directive';
1617
import { IgxGridSelectionService } from '../selection/selection.service';
@@ -29,6 +30,9 @@ const MINIMUM_COLUMN_WIDTH = 200;
2930
})
3031
export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
3132

33+
@Input()
34+
public pivotRowWidths: number;
35+
3236
/**
3337
* @hidden @internal
3438
*/
@@ -38,8 +42,8 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
3842
/**
3943
* @hidden @internal
4044
*/
41-
@ViewChild('headerTemplateGray', { read: TemplateRef, static: true })
42-
public headerTemplateGray: TemplateRef<any>;
45+
@ViewChild('headerDefaultTemplate', { read: TemplateRef, static: true })
46+
public headerTemplateDefault: TemplateRef<any>;
4347

4448
public rowDimensionData: IPivotDimensionData[] = [];
4549

@@ -79,19 +83,31 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
7983
return this.grid.gridAPI.get_row_expansion_state(this.getRowDimensionKey(col));
8084
}
8185

86+
public getLevel(col: IgxColumnComponent) {
87+
return this.data[col.field + '_level'];
88+
}
89+
8290

8391
/**
8492
* @hidden
8593
* @internal
8694
*/
8795
public ngOnChanges(changes: SimpleChanges) {
88-
if (changes.data) {
96+
const rowDimConfig = this.grid.rowDimensions;
97+
if (changes.data || rowDimConfig.length !== this.rowDimensionData.length) {
8998
// generate new rowDimension on row data change
9099
this.rowDimensionData = [];
91-
const rowDimConfig = this.grid.rowDimensions;
92100
this.viewRef.clear();
93101
this.extractFromDimensions(rowDimConfig, 0);
94102
}
103+
if (changes.pivotRowWidths && this.rowDimensionData) {
104+
for (const dim of rowDimConfig) {
105+
const dimData = PivotUtil.getDimensionLevel(dim, this.data,
106+
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'});
107+
const data = this.rowDimensionData.find(x => x.dimension.memberName === dimData.dimension.memberName);
108+
data.column.width = this.grid.resolveRowDimensionWidth(dim) + 'px';
109+
}
110+
}
95111
}
96112

97113
public getCellClass(col: any) {
@@ -114,7 +130,7 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
114130
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'});
115131
dimIndex += dimData.level;
116132
currentLvl += dimData.level;
117-
const column = this.extractFromDimension(dimData.dimension, dimIndex, currentLvl);
133+
const column = this.extractFromDimension(dimData.dimension, dimIndex, currentLvl, dim);
118134
this.rowDimensionData.push({
119135
column,
120136
dimension: dimData.dimension,
@@ -124,23 +140,24 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
124140
}
125141
}
126142

127-
protected extractFromDimension(dim: IPivotDimension, index: number = 0, lvl = 0) {
143+
protected extractFromDimension(dim: IPivotDimension, index: number = 0, lvl = 0, rootDim: IPivotDimension) {
128144
const field = dim.memberName;
129145
const header = this.data[field];
130-
const col = this._createColComponent(field, header, index, dim, lvl);
146+
const col = this._createColComponent(field, header, index, dim, lvl, rootDim);
131147
return col;
132148
}
133149

134-
protected _createColComponent(field: string, header: string, index: number = 0, dim: IPivotDimension, lvl = 0) {
150+
protected _createColComponent(field: string, header: string, index: number = 0,
151+
dim: IPivotDimension, lvl = 0, rootDim: IPivotDimension) {
135152
const ref = this.viewRef.createComponent(IgxColumnComponent);
136153
ref.instance.field = field;
137154
ref.instance.header = header;
138-
ref.instance.width = MINIMUM_COLUMN_WIDTH + 'px';
155+
ref.instance.width = this.grid.resolveRowDimensionWidth(rootDim) + 'px';
139156
(ref as any).instance._vIndex = this.grid.columns.length + index + this.index * this.grid.pivotConfiguration.rows.length;
140157
if (dim.childLevel && lvl >= PivotUtil.getTotalLvl(this.data)) {
141158
ref.instance.headerTemplate = this.headerTemplate;
142-
} else if (lvl < PivotUtil.getTotalLvl(this.data)) {
143-
ref.instance.headerTemplate = this.headerTemplateGray;
159+
} else {
160+
ref.instance.headerTemplate = this.headerTemplateDefault;
144161
}
145162
return ref.instance;
146163
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class PivotGridSampleComponent {
7979
enabled: true,
8080
childLevel: {
8181
enabled: true,
82-
memberName: 'Seller'
82+
memberName: 'SellerName'
8383
}
8484
},
8585
];

0 commit comments

Comments
 (0)