nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.33k stars 1.07k forks source link

fractionOf Total aggregator not working in pivotUI #1314

Closed ausfas closed 1 year ago

ausfas commented 1 year ago

I'm trying to use fractionOf... total but its not working:

$(function () {
    var derivers = $.pivotUtilities.derivers;
    var numberFormat = $.pivotUtilities.numberFormat;
    var intFormat = numberFormat({
            digitsAfterDecimal : 0
        });
    var tpl = $.pivotUtilities.aggregatorTemplates;
    var sum = $.pivotUtilities.aggregatorTemplates.sum;

    var usFmtPct = numberFormat({
            digitsAfterDecimal : 1,
            scaler : 100,
            suffix : "%"
        })
        var fractionOfTotalSum = $.pivotUtilities.aggregatorTemplates.fractionOf(sum(), 'total', usFmtPct)
    };
    var renderers = $.extend(
            $.pivotUtilities.renderers,

    var lstaggregators = {

        "Total Cost" : function () {
            return tpl.sum()(["Total"])
        },

        "Sum as Fraction of Total Cost" : tpl.fractionOf(tpl.sum()(["Cost"]), "total", usFmtPct),
    };

    var parseAndPivot = function (f) {
        $("#output").html("<p align='center' style='color:grey;'>(processing...)</p>")
        Papa.parse(f, {
            skipEmptyLines : true,
            error : function (e) {
                alert(e)
            },
            complete : function (parsed) {
                $("#output").pivotUI(parsed.data, {
                aggregators : lstaggregators,

and getting error:

Uncaught TypeError: wrapped.apply(...) is not a function

I've tried replicating https://github.com/nicolaskruchten/pivottable/issues/504 but still not working Sum works fine

ausfas commented 1 year ago

should be function(){return tpl.fractionOf(tpl.sum(), "total", usFmtPct)(["Cost"])} If anyone having the same issue :)