Creating Pivot Tables in JavaScript
the usage example can be seen in ./index.html
an example dataset can be seen in ./dataset/mps.json though it's just a simple array of json objects (preferably of the same structure)
[
{"Province": "Quebec", "Party": "NDP", "Age": 22, "Name": "Liu, Laurin", "Gender": "Female"},
{"Province": "Quebec", "Party": "Bloc Quebecois", "Age": 43, "Name": "Mourani, Maria", "Gender": "Female"}
]
var model = new Model(
['_row','am','carb','cyl','disp','drat','gear','hp','mpg','qsec','vs','wt'],
dataset
);
a model should contain columns list as a first variable, and the dataset as a second
var query = new Query();
there is a ready example of a query, but you can craete your own with a simmilar interface
var renderer = new PivotTableRenderer(
$('.container'),
query,
model,
['Party', 'Gender Imbalance'],
['Age Bin', 'Gender']
);
last two arguments represent rows and columns to group by the data
renderer.render(function(model) { return model.getDataset().length; });
and aggregation function gets model (representing a dataset of a given grouping) as first parameter
- add custom events/classes for binding additional functionality to the table
- add promises for data manipulation within the renderer