Skip to content

Commit 1dcdb3e

Browse files
MKirovaMKirova
authored andcommitted
feat(igxPivot): Add apis for insert/move/remove/toggle values in pivot.
1 parent 431fce7 commit 1dcdb3e

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ export interface PivotGridType extends GridType {
640640
moveDimension(dimension: IPivotDimension, targetCollectionType: PivotDimensionType, index? : number);
641641
getDimensionsByType(dimension: PivotDimensionType);
642642
toggleDimension(dimension: IPivotDimension);
643+
toggleValue(value: IPivotValue);
644+
moveValue(value: IPivotValue, index?: number);
643645
dimensionsChange: EventEmitter<IDimensionsChange>;
644646
valuesChange: EventEmitter<IValuesChange>;
645647
pivotKeys: IPivotKeys;

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

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,20 +1131,85 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11311131
this.dimensionsChange.emit({ dimensions: collection, dimensionCollectionType: dimType });
11321132
}
11331133

1134+
/**
1135+
* Inserts value at specified index or at the end.
1136+
*
1137+
* @example
1138+
* ```typescript
1139+
* this.grid.insertValueAt(value, 1);
1140+
* ```
1141+
* @param value The value definition that will be added.
1142+
* @param index The index in the collection at which to add.
1143+
* This parameter is optional. If not set it will add it to the end of the collection.
1144+
*/
11341145
public insertValueAt(value: IPivotValue, index?: number) {
1135-
1146+
if (!this.pivotConfiguration.values) {
1147+
this.pivotConfiguration.values = [];
1148+
}
1149+
const values = this.pivotConfiguration.values;
1150+
if (index !== undefined) {
1151+
values.splice(index, 0, value);
1152+
} else {
1153+
values.push(value);
1154+
}
1155+
this.setupColumns();
1156+
this.pipeTrigger++;
1157+
this.valuesChange.emit({ values });
11361158
}
11371159

1138-
public moveValue(dimension: IPivotValue, index?: number) {
1139-
1160+
/**
1161+
* Move value from its currently at specified index or at the end.
1162+
*
1163+
* @example
1164+
* ```typescript
1165+
* this.grid.moveValue(value, 1);
1166+
* ```
1167+
* @param value The value that will be moved.
1168+
* @param index The index in the collection at which to add.
1169+
* This parameter is optional. If not set it will add it to the end of the collection.
1170+
*/
1171+
public moveValue(value: IPivotValue, index?: number) {
1172+
// remove from old index
1173+
this.removeValue(value);
1174+
// add to new
1175+
this.insertValueAt(value, index);
11401176
}
11411177

1178+
/**
1179+
* Removes value from collection.
1180+
* @remarks
1181+
* This is different than toggleValue that enabled/disables the value.
1182+
* This completely removes the specified value from the collection.
1183+
* @example
1184+
* ```typescript
1185+
* this.grid.removeValue(dimension);
1186+
* ```
1187+
* @param value The value to be removed.
1188+
*/
11421189
public removeValue(value: IPivotValue,) {
1143-
1190+
const values = this.pivotConfiguration.values;
1191+
const currentIndex = values.indexOf(value);
1192+
values.splice(currentIndex, 1);
1193+
this.setupColumns();
1194+
this.pipeTrigger++;
1195+
this.valuesChange.emit({ values });
11441196
}
11451197

1198+
/**
1199+
* Toggles the value's enabled state on or off.
1200+
* @remarks
1201+
* The value remains in its current collection. This just changes its enabled state.
1202+
* @example
1203+
* ```typescript
1204+
* this.grid.toggleValue(value);
1205+
* ```
1206+
* @param value The value to be toggled.
1207+
*/
11461208
public toggleValue(value: IPivotValue) {
1147-
1209+
value.enabled = !value.enabled;
1210+
this.setupColumns();
1211+
this.pipeTrigger++;
1212+
this.valuesChange.emit({ values: this.pivotConfiguration.values });
11481213
}
11491214

11501215
public getDimensionsByType(dimension: PivotDimensionType) {

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
270270
*/
271271
public valueRemoved(event: IBaseChipEventArgs) {
272272
const value = this.grid.pivotConfiguration.values.find(x => x.member === event.owner.id || x.displayName === event.owner.id);
273-
value.enabled = false;
274-
this.grid.setupColumns();
275-
this.grid.pipeTrigger++;
276-
this.grid.valuesChange.emit({ values: this.grid.pivotConfiguration.values });
273+
this.grid.toggleValue(value);
277274
}
278275

279276
/**
@@ -429,18 +426,15 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
429426
*/
430427
public onValueDrop(event, area) {
431428
//values can only be reordered
432-
const currentDim = this.grid.pivotConfiguration.values;
429+
const values = this.grid.pivotConfiguration.values;
433430
const dragId = event.dragChip?.id || event.dragData?.chip.id;
434431
const chipsArray = area.chipsList.toArray();
435432
let chipIndex = chipsArray.indexOf(event.owner) !== -1 ? chipsArray.indexOf(event.owner) : chipsArray.length;
436433
chipIndex = this._dropPos === DropPosition.AfterDropTarget ? chipIndex + 1 : chipIndex;
437-
const newDim = currentDim.find(x => x.member === dragId || x.displayName === dragId);
438-
if (newDim) {
434+
const value = values.find(x => x.member === dragId || x.displayName === dragId);
435+
if (value) {
439436
const dragChipIndex = chipsArray.indexOf(event.dragChip || event.dragData.chip);
440-
currentDim.splice(dragChipIndex, 1);
441-
currentDim.splice(dragChipIndex >= chipIndex ? chipIndex : chipIndex - 1, 0, newDim);
442-
this.grid.setupColumns();
443-
this.grid.valuesChange.emit({ values: this.grid.pivotConfiguration.values });
437+
this.grid.moveValue(value, dragChipIndex >= chipIndex ? chipIndex : chipIndex - 1);
444438
}
445439
}
446440

0 commit comments

Comments
 (0)