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.36k stars 1.08k forks source link

Summarizing multiple keys in multiple rows #912

Open hgschehl opened 6 years ago

hgschehl commented 6 years ago

Hi! I'm wondering how I could get the following type of pivot-table:

My data is (actually) an array of objects with - amongst many others - 5 "interesting" keys with number values each, e. g.:

data=[
{title:"project1",year:2016,projectcost:10000,sponsorship:10000,expenditures:8000,payment:1000,responsible:"Paul"},
{title:"project2",year:2017,projectcost:30000,sponsorship:12000,expenditures:4000,payment:3000,responsible:"Tom"}
]

I would like to summarize all the project cost values over the respective years in one row, all sponsorship values in the 2nd row and so on:

grafik

Do I have to write my own aggregator or am I only too blind to see the OOTB-solution? Or has anyone solved this already? What I would like to avoid is running an additional query (actuallay don't have an idea how this has to look like) against my database because it would result in transferring much more IMO unneccesary data, as I have to transfer the a.m. structure anyway.

Thanks in advance! Hans-Gerhard

nicolaskruchten commented 6 years ago

What you're describing here isn't really a pivot table, or at least it's not possible to generate this output given the data you have. Your data would need to be of a structure like:

[
{year: 2016, rows: 'project cost', value: 1234},
{year: 2016, rows: 'sponsorship', value: 7890},
etc
]
hgschehl commented 6 years ago

Drat! I feared an answer like this....

But thanks for your immediate response and of course your phantastic library (already using it in the "right way" :-)! HG