PivotTable.js: a JavaScript Pivot Table implementation
github.com
github.com
My next project was to build something very similar to this. I've done the same before in PHP many years ago for the company I used to work for so I was confident that I could do it. Having this to leap frog my development is going to be extremely useful. And by that, I mean any extras I'd develop I'd contribute back.
Now to start playing.
I also feel like CoffeeScript encourages incredibly complex practices just because the code can be written in a small amount of space. For example, here's a block of code from the library in question:
sumOverSumBound80: (sigfig=3, scaler=1, upper=true) -> ([num, denom]) -> ->
sumNum: 0
sumDenom: 0
push: (row) ->
@sumNum += parseFloat(row[num]) if not isNaN parseFloat(row[num])
@sumDenom += parseFloat(row[denom]) if not isNaN parseFloat(row[denom])
value: ->
sign = if upper then 1 else -1
(0.821187207574908/@sumDenom + @sumNum/@sumDenom + 1.2815515655446004*sign*
Math.sqrt(0.410593603787454/ (@sumDenom*@sumDenom) + (@sumNum*(1 - @sumNum/ @sumDenom))/ (@sumDenom*@sumDenom)))/
(1 + 1.642374415149816/@sumDenom)
format: numberFormat(sigfig, scaler)
Have fun reading that... I think claims that CoffeeScript is a write-only language have very legitimate ground. sumOverSumBound80: (sigfig=3, scaler=1, upper=true) -> ([num, denom]) -> ->
The many arrows in the first line are confusing to me.http://nodejsreactions.tumblr.com/post/51550250985/discoveri...
The pivot table needs an aggregator object per cell, so we need a factory-function to provide one (this is the right-most arrow).
That function needs to know which columns to use as the numerator and denominator, without these being passed in on every invocation, so I used a function-generator that closes over those two values.
The third, almost gratuitous layer of function calls allows one to parametrically generate this function-generator with different formatting options.
Note that this is not an argument against coffeescript as a language. Use it if you want. Just realize that calling things ".js" when they are not is both confusing to newcomers and those expecting to read a lib written in js.
than the example that was provided.
Also check out Saiku:
http://demo.analytical-labs.com/
Talks to OLAP server over XMLA (like Mondrian)
"The term pivot table is a generic phrase used by multiple vendors. In the United States, Microsoft Corporation has trademarked the specific form PivotTable."[1]
webpivottable.com
We are working on something similar to enhance our app's existing custom reporting features. While we're erring in the side of "client side will be fine for our current requirements" if you don't mind the extra state storage server-side (or extra database hits to re-collect the data from the back-end each time) you could keep the data there and pull the results back via AJAX calls - with careful design you could even be share the slicing/dicing code between client & server and make the choice dynamically (if the data is small send it all to the client then you are as responsive as possible, if it is above a certain payload size keep it server-side to improve load time at the expense of interactive latency due to the AJAX calls as the user plays with the data). And/Or you could give the user the choice.
We routinely use this tool to summarize datasets which are, at their most disaggregated, hundreds of millions of rows. We have a server-side process which rolls those up into hundreds of thousands of rows, which are then fed to the browser via a query interface which tends to send only a few thousand at a time, which is easily handled by this tool.
Each step in this pipeline 'summarizes' to an extent, and the last mile is this interactive client-side tool, which would be less responsive if it were server-side.