@@ -31,7 +31,7 @@ import { IgxForOfSyncService, IgxForOfScrollSyncService } from '../../directives
31
31
import { ColumnType , GridType , IGX_GRID_BASE , RowType } from '../common/grid.interface' ;
32
32
import { IgxGridCRUDService } from '../common/crud.service' ;
33
33
import { IgxGridSummaryService } from '../summaries/grid-summary.service' ;
34
- import { DEFAULT_PIVOT_KEYS , IDimensionsChange , IPivotConfiguration , IPivotDimension , IValuesChange , PivotDimensionType } from './pivot-grid.interface' ;
34
+ import { DEFAULT_PIVOT_KEYS , IDimensionsChange , IPivotConfiguration , IPivotDimension , IPivotValue , IValuesChange , PivotDimensionType } from './pivot-grid.interface' ;
35
35
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component' ;
36
36
import { IgxColumnGroupComponent } from '../columns/column-group.component' ;
37
37
import { IgxColumnComponent } from '../columns/column.component' ;
@@ -128,11 +128,11 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
128
128
* <igx-pivot-grid [pivotConfiguration]="config"></igx-pivot-grid>
129
129
* ```
130
130
*/
131
- public set pivotConfiguration ( value : IPivotConfiguration ) {
131
+ public set pivotConfiguration ( value : IPivotConfiguration ) {
132
132
this . _pivotConfiguration = value ;
133
133
this . notifyChanges ( true ) ;
134
134
}
135
-
135
+
136
136
public get pivotConfiguration ( ) {
137
137
return this . _pivotConfiguration ;
138
138
}
@@ -774,7 +774,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
774
774
}
775
775
776
776
public get values ( ) {
777
- return this . pivotConfiguration . values . filter ( x => x . enabled ) ;
777
+ return this . pivotConfiguration . values . filter ( x => x . enabled ) || [ ] ;
778
778
}
779
779
780
780
public toggleColumn ( col : IgxColumnComponent ) {
@@ -1049,12 +1049,224 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1049
1049
}
1050
1050
}
1051
1051
1052
+ /**
1053
+ * Inserts dimension in target collection by type at specified index or at the collection's end.
1054
+ *
1055
+ * @example
1056
+ * ```typescript
1057
+ * this.grid.insertDimensionAt(dimension, PivotDimensionType.Row, 1);
1058
+ * ```
1059
+ * @param dimension The dimension that will be added.
1060
+ * @param targetCollectionType The target collection type to add to. Can be Row, Column or Filter.
1061
+ * @param index The index in the collection at which to add.
1062
+ * This parameter is optional. If not set it will add it to the end of the collection.
1063
+ */
1064
+ public insertDimensionAt ( dimension : IPivotDimension , targetCollectionType : PivotDimensionType , index ?: number ) {
1065
+ const targetCollection = this . getDimensionsByType ( targetCollectionType ) ;
1066
+ if ( index !== undefined ) {
1067
+ targetCollection . splice ( index , 0 , dimension ) ;
1068
+ } else {
1069
+ targetCollection . push ( dimension ) ;
1070
+ }
1071
+ if ( targetCollectionType === PivotDimensionType . Column ) {
1072
+ this . setupColumns ( ) ;
1073
+ }
1074
+ this . pipeTrigger ++ ;
1075
+ this . dimensionsChange . emit ( { dimensions : targetCollection , dimensionCollectionType : targetCollectionType } ) ;
1076
+ if ( targetCollectionType === PivotDimensionType . Filter ) {
1077
+ this . reflow ( ) ;
1078
+ }
1079
+ }
1080
+
1081
+ /**
1082
+ * Move dimension from its currently collection to the specified target collection by type at specified index or at the collection's end.
1083
+ *
1084
+ * @example
1085
+ * ```typescript
1086
+ * this.grid.moveDimension(dimension, PivotDimensionType.Row, 1);
1087
+ * ```
1088
+ * @param dimension The dimension that will be moved.
1089
+ * @param targetCollectionType The target collection type to move it to. Can be Row, Column or Filter.
1090
+ * @param index The index in the collection at which to add.
1091
+ * This parameter is optional. If not set it will add it to the end of the collection.
1092
+ */
1093
+ public moveDimension ( dimension : IPivotDimension , targetCollectionType : PivotDimensionType , index ?: number ) {
1094
+ const prevCollectionType = this . getDimensionType ( dimension ) ;
1095
+ if ( prevCollectionType === null ) return ;
1096
+ // remove from old collection
1097
+ this . removeDimension ( dimension ) ;
1098
+ // add to target
1099
+ this . insertDimensionAt ( dimension , targetCollectionType , index ) ;
1100
+ }
1101
+
1102
+ /**
1103
+ * Removes dimension from its currently collection.
1104
+ * @remarks
1105
+ * This is different than toggleDimension that enabled/disables the dimension.
1106
+ * This completely removes the specified dimension from the collection.
1107
+ * @example
1108
+ * ```typescript
1109
+ * this.grid.removeDimension(dimension);
1110
+ * ```
1111
+ * @param dimension The dimension to be removed.
1112
+ */
1113
+ public removeDimension ( dimension : IPivotDimension ) {
1114
+ const prevCollectionType = this . getDimensionType ( dimension ) ;
1115
+ if ( prevCollectionType === null ) return ;
1116
+ const prevCollection = this . getDimensionsByType ( prevCollectionType ) ;
1117
+ const currentIndex = prevCollection . indexOf ( dimension ) ;
1118
+ prevCollection . splice ( currentIndex , 1 ) ;
1119
+ if ( prevCollectionType === PivotDimensionType . Column ) {
1120
+ this . setupColumns ( ) ;
1121
+ }
1122
+ if ( prevCollectionType === PivotDimensionType . Filter ) {
1123
+ this . reflow ( ) ;
1124
+ }
1125
+ this . pipeTrigger ++ ;
1126
+ this . cdr . detectChanges ( ) ;
1127
+ }
1128
+
1129
+ /**
1130
+ * Toggles the dimension's enabled state on or off.
1131
+ * @remarks
1132
+ * The dimension remains in its current collection. This just changes its enabled state.
1133
+ * @example
1134
+ * ```typescript
1135
+ * this.grid.toggleDimension(dimension);
1136
+ * ```
1137
+ * @param dimension The dimension to be toggled.
1138
+ */
1139
+ public toggleDimension ( dimension : IPivotDimension ) {
1140
+ const dimType = this . getDimensionType ( dimension ) ;
1141
+ if ( dimType === null ) return ;
1142
+ const collection = this . getDimensionsByType ( dimType ) ;
1143
+ dimension . enabled = ! dimension . enabled ;
1144
+ if ( dimType === PivotDimensionType . Column ) {
1145
+ this . setupColumns ( ) ;
1146
+ }
1147
+ if ( ! dimension . enabled ) {
1148
+ this . filteringService . clearFilter ( dimension . memberName ) ;
1149
+ }
1150
+ this . pipeTrigger ++ ;
1151
+ this . dimensionsChange . emit ( { dimensions : collection , dimensionCollectionType : dimType } ) ;
1152
+ }
1153
+
1154
+ /**
1155
+ * Inserts value at specified index or at the end.
1156
+ *
1157
+ * @example
1158
+ * ```typescript
1159
+ * this.grid.insertValueAt(value, 1);
1160
+ * ```
1161
+ * @param value The value definition that will be added.
1162
+ * @param index The index in the collection at which to add.
1163
+ * This parameter is optional. If not set it will add it to the end of the collection.
1164
+ */
1165
+ public insertValueAt ( value : IPivotValue , index ?: number ) {
1166
+ if ( ! this . pivotConfiguration . values ) {
1167
+ this . pivotConfiguration . values = [ ] ;
1168
+ }
1169
+ const values = this . pivotConfiguration . values ;
1170
+ if ( index !== undefined ) {
1171
+ values . splice ( index , 0 , value ) ;
1172
+ } else {
1173
+ values . push ( value ) ;
1174
+ }
1175
+ this . setupColumns ( ) ;
1176
+ this . pipeTrigger ++ ;
1177
+ this . cdr . detectChanges ( ) ;
1178
+ this . valuesChange . emit ( { values } ) ;
1179
+ }
1180
+
1181
+ /**
1182
+ * Move value from its currently at specified index or at the end.
1183
+ *
1184
+ * @example
1185
+ * ```typescript
1186
+ * this.grid.moveValue(value, 1);
1187
+ * ```
1188
+ * @param value The value that will be moved.
1189
+ * @param index The index in the collection at which to add.
1190
+ * This parameter is optional. If not set it will add it to the end of the collection.
1191
+ */
1192
+ public moveValue ( value : IPivotValue , index ?: number ) {
1193
+ if ( this . pivotConfiguration . values . indexOf ( value ) === - 1 ) return ;
1194
+ // remove from old index
1195
+ this . removeValue ( value ) ;
1196
+ // add to new
1197
+ this . insertValueAt ( value , index ) ;
1198
+ }
1199
+
1200
+ /**
1201
+ * Removes value from collection.
1202
+ * @remarks
1203
+ * This is different than toggleValue that enabled/disables the value.
1204
+ * This completely removes the specified value from the collection.
1205
+ * @example
1206
+ * ```typescript
1207
+ * this.grid.removeValue(dimension);
1208
+ * ```
1209
+ * @param value The value to be removed.
1210
+ */
1211
+ public removeValue ( value : IPivotValue , ) {
1212
+ const values = this . pivotConfiguration . values ;
1213
+ const currentIndex = values . indexOf ( value ) ;
1214
+ if ( currentIndex !== - 1 ) {
1215
+ values . splice ( currentIndex , 1 ) ;
1216
+ this . setupColumns ( ) ;
1217
+ this . pipeTrigger ++ ;
1218
+ this . valuesChange . emit ( { values } ) ;
1219
+ }
1220
+ }
1221
+
1222
+ /**
1223
+ * Toggles the value's enabled state on or off.
1224
+ * @remarks
1225
+ * The value remains in its current collection. This just changes its enabled state.
1226
+ * @example
1227
+ * ```typescript
1228
+ * this.grid.toggleValue(value);
1229
+ * ```
1230
+ * @param value The value to be toggled.
1231
+ */
1232
+ public toggleValue ( value : IPivotValue ) {
1233
+ if ( this . pivotConfiguration . values . indexOf ( value ) === - 1 ) return ;
1234
+ value . enabled = ! value . enabled ;
1235
+ this . setupColumns ( ) ;
1236
+ this . pipeTrigger ++ ;
1237
+ this . valuesChange . emit ( { values : this . pivotConfiguration . values } ) ;
1238
+ }
1239
+
1240
+ public getDimensionsByType ( dimension : PivotDimensionType ) {
1241
+ switch ( dimension ) {
1242
+ case PivotDimensionType . Row :
1243
+ if ( ! this . pivotConfiguration . rows ) {
1244
+ this . pivotConfiguration . rows = [ ] ;
1245
+ }
1246
+ return this . pivotConfiguration . rows ;
1247
+ case PivotDimensionType . Column :
1248
+ if ( ! this . pivotConfiguration . columns ) {
1249
+ this . pivotConfiguration . columns = [ ] ;
1250
+ }
1251
+ return this . pivotConfiguration . columns ;
1252
+ case PivotDimensionType . Filter :
1253
+ if ( ! this . pivotConfiguration . filters ) {
1254
+ this . pivotConfiguration . filters = [ ] ;
1255
+ }
1256
+ return this . pivotConfiguration . filters ;
1257
+ default :
1258
+ return null ;
1259
+ }
1260
+ }
1261
+
1262
+
1052
1263
@ViewChildren ( IgxPivotRowDimensionContentComponent )
1053
1264
protected rowDimensionContentCollection : QueryList < IgxPivotRowDimensionContentComponent > ;
1054
1265
1055
1266
protected getDimensionType ( dimension : IPivotDimension ) : PivotDimensionType {
1056
1267
return PivotUtil . flatten ( this . rowDimensions ) . indexOf ( dimension ) !== - 1 ? PivotDimensionType . Row :
1057
- PivotUtil . flatten ( this . columnDimensions ) . indexOf ( dimension ) !== - 1 ? PivotDimensionType . Column : PivotDimensionType . Filter ;
1268
+ PivotUtil . flatten ( this . columnDimensions ) . indexOf ( dimension ) !== - 1 ? PivotDimensionType . Column :
1269
+ PivotUtil . flatten ( this . filterDimensions ) . indexOf ( dimension ) !== - 1 ? PivotDimensionType . Filter : null ;
1058
1270
}
1059
1271
1060
1272
protected getLargesContentWidth ( contents : ElementRef [ ] ) : string {
@@ -1154,6 +1366,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1154
1366
*/
1155
1367
protected autogenerateColumns ( ) {
1156
1368
let columns = [ ] ;
1369
+ this . filterStrategy = this . filterStrategy ?? new DimensionValuesFilteringStrategy ( ) ;
1157
1370
const data = this . gridAPI . filterDataByExpressions ( this . filteringExpressionsTree ) ;
1158
1371
this . dimensionDataColumns = this . generateDimensionColumns ( ) ;
1159
1372
let fieldsMap ;
0 commit comments