-
Notifications
You must be signed in to change notification settings - Fork 46
Getting Started
Subtotal.js is a JavaScript plugin for PivotTable.js. It renders rows and columns of a pivot table with subtotals and lets the user expand or collapse rows and columns.
Subtotal.js is available under an MIT license from NPM and Bower under the name subtotal
. On packagist.org, it is nagarajanchinnasamy/subtotal
.
You can see the live demo at examples page.
Subtotal.js implements the Universal Module Definition (UMD) pattern and so should be compatible with most approaches to script loading and dependency management: direct script loading with RequireJS, Browserify etc. For these options, you can grab it from NPM with npm install subtotal
or via Bower with bower install subtotal
.
If you are loading the scripts directly (as in the examples), you need to:
- load the dependencies:
- jQuery in all cases
- jQueryUI for the interactive
pivotUI()
function (see below) - D3.js, C3.js and/or Google Charts if you use charting plugins
- load the PivotTable.js files:
pivot.min.js
- load the Subtotal.js files:
subtotal.min.js
Here is the source code of an exmaple
You can use Subtotal.js with either pivot()
or pivotUI()
method of PivotTable.js.
- Set the value of
dataClass
parameter to$.pivotUtilities.SubtotalPivotData
- Set the value of
renderer
parameter to$.pivotUtilities.subtotal_renderers[<*rendererName*>]
- Optionally, set
rendererOptions
$(function(){
$.getJSON("mps.json", function(mps) {
$("#output").pivot(mps, {
dataClass: $.pivotUtilities.SubtotalPivotData,
rows: ["Gender", "Province"],
cols: ["Party", "Age"],
renderer: $.pivotUtilities.subtotal_renderers["Table With Subtotal"],
rendererOptions: {
arrowExpanded: "[+]",
arrowCollapsed: "[-]",
rowSubtotalDisplay: {
collapseAt: 0
},
colSubtotalDisplay: {
collapseAt: 0
}
}
});
});
});
- Set the value of
dataClass
parameter to$.pivotUtilities.SubtotalPivotData
- Set the value of
renderers
parameter to$.pivotUtilities.subtotal_renderers
- Set the value of
rendererName
parameter to one of the subtotal renderers name - Optionally, set
rendererOptions
$(function(){
$.getJSON("mps.json", function(mps) {
$("#output").pivotUI(mps, {
dataClass: $.pivotUtilities.SubtotalPivotData,
rows: ["Gender", "Province"],
cols: ["Party", "Age"],
renderers: $.pivotUtilities.subtotal_renderers,
rendererName: "Table With Subtotal",
rendererOptions: {
arrowExpanded: "[+]",
arrowCollapsed: "[-]",
rowSubtotalDisplay: {
collapseAt: 0
},
colSubtotalDisplay: {
collapseAt: 0
}
}
});
});
});