- wrap all table renderers for pivot UI
- uses NReco extension features: sort (asc/desc), fixed headers
- save/load report state
var nrecoPivotExt = new NRecoPivotTableExtensions({
wrapWith: '<div class="pvtTableRendererHolder">>/div>',
fixedHeaders : true,
onSortHandler : function(sortOpts) {
// save changed sort options in pivotUI state
// this handler is needed only if you need to save state of user-configured report
var pvtUIOpts = $('#samplePivotTable2').data("pivotUIOptions");
if (!pvtUIOpts.rendererOptions) pvtUIOpts.rendererOptions = {};
pvtUIOpts.rendererOptions.sort = sortOpts;
}
});
var nrecoPivotExt = new NRecoPivotTableExtensions({
fixedHeaders : true
});
var stdRendererNames = ["Table","Table Barchart",
"Heatmap","Row Heatmap","Col Heatmap"];
var wrappedRenderers = $.extend( {}, $.pivotUtilities.renderers);
$.each(stdRendererNames, function() {
var rName = this;
wrappedRenderers[rName] =
nrecoPivotExt.wrapTableRenderer(wrappedRenderers[rName]);
});
$('#samplePivotTable2').pivotUI(sampleData, {
renderers: wrappedRenderers,
// pivot table sort state, leave empty to apply default order (labels A-Z)
rendererOptions: { sort: { direction : "desc", column_key : [ 2014 ]} },
// pivot table setup
vals: ["Total"],
rows: ["Country"],
cols: ["Year"],
aggregatorName : "Sum",
onRefresh: function (pivotUIOptions) {
nrecoPivotExt.initFixedHeaders(
$('#samplePivotTable2 table.pvtTable'));
}
});