Web Components Pivot Grid Overview
Ignite UI for Web Components Pivot Grids are used for summing up and representing voluminous multidimensional data in a cross-tabular format. The data summery can be easily and quickly sorted, grouped, or filtered. Such data can include sums, averages, and other statistics. End-users are enabled to modify the pivot table layout through drag-and-drop operations, according to their needs.
What is Web Components Pivot Grid?
The Web Components IgcPivotGrid presents data in a pivot table and helps performing complex analysis on the supplied data set. This sophisticated Pivot Grid control is used for organizing, summarizing, and filtering large volumes of data which is later displayed in a cross-table format. Key features of an Web Components Pivot Grid are row dimensions, column dimensions, aggregations, and filters.
The IgcPivotGridComponent
gives the ability to users to configure and display their data in a multi-dimensional pivot table structure.
The rows and columns represent distinct data groups, and the data cell values represent aggregations. This allows complex data analysis based on a simple flat data set. The IgcPivotGridComponent
is a feature-rich pivot table that provides easy configuration of the different dimensions and values as well as additional data operations on them like filtering and sorting.
Web Components Pivot Grid Example
The following is an Web Components Pivot Grid example in combination with the Web Components Pivot Data Selector Component. This way you can have more flexible runtime configuration options.
Getting Started With Web Components Pivot Grid
The Web Components IgcPivotGrid can be configured via the pivotConfiguration
property.
<igc-pivot-grid #grid1 data="data" pivot-configuration="pivotConfigHierarchy">
</igc-pivot-grid>
It is defined by three main dimensions: rows, columns and values. The rows and columns define the grouped structure that is displayed in the rows and columns of the grid. The values define the aggregation fields and the aggregation that will be used to calculate and display the related values of the groups.
A filter can also be defined via the filters configuration property. It can be used for fields that you do not want to add as a dimension or a value but would like to filter their related member values via the UI.
Dimensions Configuration
Each basic dimension configuration requires a MemberName
that matches a field from the provided data.
public pivotConfigHierarchy: IgcPivotConfiguration = {
rows: [
new IgcPivotDateDimension({ memberName: 'Date', enabled: true });
]
}
It also allows for further customization via the second option parameter in order to enable or disable a particular part of the hierarchy, for example:
new IgcPivotDateDimension({ memberName: 'Date', enabled: true }, {
total: true,
years: true,
months: true,
fullDate: true,
quarters: false
});
Values Configuration
A value configuration requires a member that matches a field from the provided data, or it can define a custom aggregator function for more complex custom scenarios. Out of the box, there are 4 predefined aggregations that can be used depending on the data type of the data field:
PivotNumericAggregate
- for numeric fields. Contains the following aggregation functions:SUM
,AVG
,MIN
,MAX
,COUNT
.PivotDateAggregate
- for date fields. Contains the following aggregation functions:LATEST
,EARLIEST
,COUNT
.PivotTimeAggregate
- for time fields. Contains the following aggregation functions:LATEST
,EARLIEST
,COUNT
.PivotAggregate
- for any other data types. This is the base aggregation. Contains the following aggregation functions:COUNT
.
The current aggregation function can be changed at runtime using the value chip's drop-down. By default, it displays a list of available aggregations based on the field's data type. A custom list of aggregations can also be set via the AggregateList
property, for example:
public pivotConfigHierarchy: IgcPivotConfiguration = {
values: [
{
member: 'AmountOfSale',
displayName: 'Amount of Sale',
aggregate: {
key: 'SUM',
aggregator: IgxTotalSaleAggregate.totalSale,
label: 'Sum of Sale'
},
aggregateList: [{
key: 'SUM',
aggregator: IgxTotalSaleAggregate.totalSale,
label: 'Sum of Sale'
}, {
key: 'MIN',
aggregator: IgxTotalSaleAggregate.totalMin,
label: 'Minimum of Sale'
}, {
key: 'MAX',
aggregator: IgxTotalSaleAggregate.totalMax,
label: 'Maximum of Sale'
}]
}
]
}
public static totalSale: PivotAggregation = (members, data: any) =>
data.reduce((accumulator, value) => accumulator + value.UnitPrice * value.UnitsSold, 0);
public static totalMin: PivotAggregation = (members, data: any) => {
return data.map(x => x.UnitPrice * x.UnitsSold).reduce((a, b) => Math.min(a, b));
};
public static totalMax: PivotAggregation = (members, data: any) => {
return data.map(x => x.UnitPrice * x.UnitsSold).reduce((a, b) => Math.max(a,b));
};
The pivot value also provides a DisplayName
property. It can be used to display a custom name for this value in the column header.
Enable Property
pivotConfiguration
is the interface that describes the current state of the IgcPivotGridComponent
component. With it the developer can declare fields of the data as rows, columns, filters or values. The configuration allows enabling or disabling each of these elements separately. Only enabled elements are included in the current state of the Pivot Grid. The IgcPivotDataSelectorComponent
component utilizes the same configuration and shows a list of all elements - enabled and disabled. For each of them there is a checkbox in the appropriate state. End-users can easily tweak the pivot state by toggling the different elements using these checkboxes.
The Enable
property controls if a given IgcPivotDimension
or IgcPivotValue
is active and takes part in the pivot view rendered by the Pivot Grid.
Full Configuration Code
Let's take a look at a basic pivot configuration:
public pivotConfigHierarchy: IgcPivotConfiguration = {
columns: [
{
memberName: 'Product',
memberFunction: (data) => data.Product.Name,
enabled: true
}
],
rows: [
{
memberName: 'Seller',
memberFunction: (data) => data.Seller.Name,
enabled: true,
}
],
values: [
{
member: 'NumberOfUnits',
aggregate: {
aggregator: IgxPivotNumericAggregate.sum,
key: 'sum',
label: 'Sum'
},
enabled: true
}
]
};
This configuration defines 1 row, 1 column and 1 aggregation that sums the values of each dimension groups. The members match fields available in the provided data source:
public data = [
[
{
Product: {
Name: 'Clothing',
UnitPrice: '12.814860936633712'
},
Seller: {
Name: 'Stanley Brooker',
City: 'Seattle'
},
Date: '2007-01-01T00:00:00',
Value: '94.2652032683907',
NumberOfUnits: '282'
},
];
Full Configuration Example
Using above code will result in the following example which groups the Product Categories unique columns, Sellers Countries in unique rows and displays the related aggregations for the number of units in the related cells:
Known Issues and Limitations
Limitation | Description |
---|---|
Setting columns declaratively is not supported. | The Pivot grid generates its columns based on the columns configuration, so setting them declaratively, like in the base grid, is not supported. Such columns are disregarded. |
Setting duplicate MemberName or member property values for dimensions/values. |
These properties should be unique for each dimension/value. Duplication may result in loss of data from the final result. |
Row Selection is only supported in Single mode. | Multiple selection is currently not supported. |
API References
pivotConfiguration
IgcPivotGridComponent
IgcPivotDataSelectorComponent
IgcPivotDateDimension
IgcColumn
Additional Resources
Our community is active and always welcoming to new ideas.