« back to PivotTable.js examples
// This example shows custom aggregators and sorters using
// the "Canadian Parliament 2012" dataset.
$(function(){
var tpl = $.pivotUtilities.aggregatorTemplates;
$.getJSON("mps.json", function(mps) {
$("#output").pivotUI(mps, {
rows: ["Province"], cols: ["Party"],
aggregators: {
"Number of MPs": function() { return tpl.count()() },
"Average Age of MPs": function() { return tpl.average()(["Age"])}
},
sorters: {
Province: $.pivotUtilities.sortAs(
["British Columbia", "Alberta",
"Saskatchewan", "Manitoba",
"Territories", "Ontario", "Quebec",
"New Brunswick", "Prince Edward Island",
"Nova Scotia", "Newfoundland and Labrador"]),
Age: function(a,b){ return b-a; } //sort backwards
}
});
});
});