Skip to content

Commit f3a94b6

Browse files
MKirovaMKirova
authored andcommitted
chore(*): In case of removing/toggling/moving a dimension/value that is not in the collections do nothing. You can only insert new dimensions/values.
1 parent 1f820ea commit f3a94b6

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
777777
}
778778

779779
public get values() {
780-
return this.pivotConfiguration.values.filter(x => x.enabled);
780+
return this.pivotConfiguration.values.filter(x => x.enabled) || [];
781781
}
782782

783783
public toggleColumn(col: IgxColumnComponent) {
@@ -1076,6 +1076,9 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10761076
}
10771077
this.pipeTrigger++;
10781078
this.dimensionsChange.emit({ dimensions: targetCollection, dimensionCollectionType: targetCollectionType });
1079+
if (targetCollectionType === PivotDimensionType.Filter) {
1080+
this.reflow();
1081+
}
10791082
}
10801083

10811084
/**
@@ -1091,6 +1094,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10911094
* This parameter is optional. If not set it will add it to the end of the collection.
10921095
*/
10931096
public moveDimension(dimension: IPivotDimension, targetCollectionType: PivotDimensionType, index?: number) {
1097+
const prevCollectionType = this.getDimensionType(dimension);
1098+
if (prevCollectionType === null) return;
10941099
// remove from old collection
10951100
this.removeDimension(dimension);
10961101
// add to target
@@ -1110,6 +1115,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11101115
*/
11111116
public removeDimension(dimension: IPivotDimension) {
11121117
const prevCollectionType = this.getDimensionType(dimension);
1118+
if (prevCollectionType === null) return;
11131119
const prevCollection = this.getDimensionsByType(prevCollectionType);
11141120
const currentIndex = prevCollection.indexOf(dimension);
11151121
prevCollection.splice(currentIndex, 1);
@@ -1134,6 +1140,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11341140
*/
11351141
public toggleDimension(dimension: IPivotDimension) {
11361142
const dimType = this.getDimensionType(dimension);
1143+
if (dimType === null) return;
11371144
const collection = this.getDimensionsByType(dimType);
11381145
dimension.enabled = !dimension.enabled;
11391146
if (dimType === PivotDimensionType.Column) {
@@ -1184,6 +1191,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11841191
* This parameter is optional. If not set it will add it to the end of the collection.
11851192
*/
11861193
public moveValue(value: IPivotValue, index?: number) {
1194+
if (this.pivotConfiguration.values.indexOf(value) === -1) return;
11871195
// remove from old index
11881196
this.removeValue(value);
11891197
// add to new
@@ -1204,10 +1212,12 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
12041212
public removeValue(value: IPivotValue,) {
12051213
const values = this.pivotConfiguration.values;
12061214
const currentIndex = values.indexOf(value);
1207-
values.splice(currentIndex, 1);
1208-
this.setupColumns();
1209-
this.pipeTrigger++;
1210-
this.valuesChange.emit({ values });
1215+
if (currentIndex !== -1) {
1216+
values.splice(currentIndex, 1);
1217+
this.setupColumns();
1218+
this.pipeTrigger++;
1219+
this.valuesChange.emit({ values });
1220+
}
12111221
}
12121222

12131223
/**
@@ -1221,6 +1231,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
12211231
* @param value The value to be toggled.
12221232
*/
12231233
public toggleValue(value: IPivotValue) {
1234+
if (this.pivotConfiguration.values.indexOf(value) === -1) return;
12241235
value.enabled = !value.enabled;
12251236
this.setupColumns();
12261237
this.pipeTrigger++;
@@ -1255,7 +1266,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
12551266

12561267
protected getDimensionType(dimension: IPivotDimension): PivotDimensionType {
12571268
return PivotUtil.flatten(this.rowDimensions).indexOf(dimension) !== -1 ? PivotDimensionType.Row :
1258-
PivotUtil.flatten(this.columnDimensions).indexOf(dimension) !== -1 ? PivotDimensionType.Column : PivotDimensionType.Filter;
1269+
PivotUtil.flatten(this.columnDimensions).indexOf(dimension) !== -1 ? PivotDimensionType.Column :
1270+
PivotUtil.flatten(this.columnDimensions).indexOf(dimension) !== -1 ? PivotDimensionType.Filter : null;
12591271
}
12601272

12611273
protected getLargesContentWidth(contents: ElementRef[]): string {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111
</igx-buttongroup>
1212
</div>
1313
<button igxButton (click)="setRowDimWidth(0, '400px')">ResizeRowDim</button>
14-
<button (click)='autoSizeRow(0)'>AutoSize Row 0</button>
15-
<button (click)='autoSizeRow(1)'>AutoSize Row 1</button>
14+
<button (click)='remove()'>Remove</button>
15+
<button (click)='toggle()'>Toggle</button>
16+
<button (click)='move()'>Move</button>
17+
<button (click)='insert()'>Insert</button>
18+
19+
<button (click)='removeVal()'>Remove</button>
20+
<button (click)='toggleVal()'>Toggle</button>
21+
<button (click)='moveVal()'>Move</button>
22+
<button (click)='insertVal()'>Insert</button>
1623
</div>
1724

1825
<igx-pivot-grid #grid1 [data]="origData" [width]="'100%'" [height]="'100%'" [defaultExpandState]='true'

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
DisplayDensity,
1212
FilteringExpressionsTree,
1313
FilteringLogic,
14-
IgxStringFilteringOperand
14+
IgxStringFilteringOperand,
15+
PivotDimensionType
1516
} from 'igniteui-angular';
1617
import { HIERARCHICAL_SAMPLE_DATA } from '../shared/sample-data';
1718

@@ -237,4 +238,56 @@ export class PivotGridSampleComponent {
237238

238239
this.grid1.pivotConfiguration = newPivotConfig;
239240
}
241+
242+
public remove(){
243+
this.grid1.removeDimension({memberName: 'test', enabled: true});
244+
}
245+
246+
public toggle(){
247+
this.grid1.toggleDimension({memberName: 'test', enabled: true});
248+
}
249+
250+
public move(){
251+
this.grid1.moveDimension({memberName: 'test', enabled: true}, PivotDimensionType.Filter, 0);
252+
}
253+
254+
public insert(){
255+
this.grid1.insertDimensionAt({
256+
memberName: 'Country',
257+
enabled: true
258+
}, PivotDimensionType.Filter, 0);
259+
}
260+
261+
262+
public removeVal(){
263+
this.grid1.removeValue({member: 'test', enabled: true, aggregate: {
264+
key: 'SUM',
265+
aggregator: IgxPivotNumericAggregate.sum,
266+
label: 'Sum'
267+
} });
268+
}
269+
270+
public toggleVal(){
271+
this.grid1.toggleValue({member: 'test', enabled: true, aggregate: {
272+
key: 'SUM',
273+
aggregator: IgxPivotNumericAggregate.sum,
274+
label: 'Sum'
275+
} });
276+
}
277+
278+
public moveVal(){
279+
this.grid1.moveValue({member: 'test', enabled: true, aggregate: {
280+
key: 'SUM',
281+
aggregator: IgxPivotNumericAggregate.sum,
282+
label: 'Sum'
283+
} }, 0);
284+
}
285+
286+
public insertVal(){
287+
this.grid1.insertValueAt({member: 'test', enabled: true, aggregate: {
288+
key: 'SUM',
289+
aggregator: IgxPivotNumericAggregate.sum,
290+
label: 'Sum'
291+
} }, 0);
292+
}
240293
}

0 commit comments

Comments
 (0)