It is possible to get the current Pivot fields object and set a new one. Use the two related methods - getFields and setFields for this purpose:
// get the current pivot fields
var fields = myPivot.getFields();
// set a new fields object
myPivot.setFields(newFields);
The setFields() method takes a fields' object as a parameter.
The newFields object in the above example has the same structure as the fields object in the Pivot constructor:
var newFields = {
rows: ["form", "name"],
columns: ["year"],
values: [
{ id: "oil", method: "max" },
{ id: "oil", method: "sum" }
]
}
All data operations are specified as objects of the values array within the Pivot fields object.
fields: {
rows: ["form", "name"],
columns: ["year"],
values: [
{ id: "oil", method: "max" }, // max value of the "oil" property will be shown
{ id: "oil", method: "sum" } // values of the "oil" property will be summed up
]
}
You can choose between four preset types of operations that you can apply for a dataset:
Read also about possibilities of configuring Pivot operations.
You can add your own operation in addition to the predefined set. For this, you have to use the addMathMethod method.
You need to pass three parameters to this method:
myPivot.addMathMethod("avr", "Avr", (cellData) => {
const sum = cellData.reduce((el, all) => all += el);
return (sum / cellData.length).toFixed(3);
});
Related sample: Custom methods
You can get the current Pivot configuration settings via the getConfig method to check whether everything is adjusted correctly:
var config = myPivot.getConfig();
The returned config object will contain all the attributes included in the Pivot configuration object.
Read about the ways of configuring Pivot in the article Configuring Pivot.
Back to top