javascriptcoffeescriptreportpivot-tablezk-grid

Web pivot table componet showing text in pivot table data area


I have found these great pivot table components on the web

nicolaskruchten - pivottable

ZKOSS - pivottable

RJackson - pivottable

My problem (or question) lies in the fact that pivot tables inherently "pivot" data around a numeric data-set; meaning the cell intersections can typically only be numeric in nature (SUM/COUNT/FIRST...)

Is there anything out there (or, if you know how to modify a current component) that will show non-numeric data within the pivot "Value" or intersection.

my question is illustrated below. enter image description here

as can be seen the interaction data is actually the reports which each role has acess to (grouped by the class of report)... I know there are other ways to represent this data, however I really like the way the pivot viewers above can swap the data filters (columns)

thanks in advance.


Solution

  • I can't speak for all the different pivot table implementations out there, some might have a built-in "aggregator" that will allow you to concatenate string values with formatting (to add a cr/lf for example), but a quick look at the nicolaskruchten/pivottable source lets me think you could easily add your own aggregator.

    Just look at file pivot.coffee, starting at line 22. You'll see different aggregator templates, so you could probably add your own right there.

    EDIT

    I just looked at the rjackson/pivot.js implementation, and by the looks of it, if you add your own defaultSummarizeFunction at pivot.js line 586+, and then also add it to the select at lines 651+, you could create your own "concat" SummarizeFunction

    EDIT 2

    Well, turns out to be even easier than I thought. Using the rjackson/pivot.js one, all you have to do is provide your own summarizeFunction when you define your concatenable field:

    {name: 'billed_amount',     type: 'string',  rowLabelable: false, summarizable: 'string', summarizeFunction: function(rows, field){ 
            var result = '',
                i = -1;
                m = rows.length;
    
            while (++i < m) {
              result = result + rows[i][field.dataSource] + '<br>';
            }
            return result;
     }}
    

    In this example, I turned a field that would normally be summed, and turned it into a concatenated one simply by providing my own summarizeFunction.

    Look at an example here: http://mrlucmorin.github.io/pivot.js/

    Cheers