I'm using dc.js library to generate graphs and I would like to be able to retrieve the filtered data when filters are applied.
Asked
Active
Viewed 889 times
2 Answers
5
Create another dimension and then call dimension.top(Infinity)
on it.
https://github.com/square/crossfilter/wiki/API-Reference#dimension_top
You will need the extra dimension because dimensions do not observe their own filters, only the filters on other dimensions.
Then you can use e.g. d3.csv.format
to produce text, if you need to.

Gordon
- 19,811
- 4
- 36
- 74
-
Yeah the thing is crossfilter – Boris Barroso Oct 08 '14 at 21:27
-
Here's a [complete example](http://dc-js.github.io/dc.js/examples/download-table.html) including a download button. Explained in [this answer](http://stackoverflow.com/a/37573744/676195). – Gordon Jun 01 '16 at 16:08
2
In the version 4 of d3.js d3.csv.format
doesn't exist, you must use d3.csvFormat
instead.
const cf = crossfilter(data);
csvDimension = cf.dimension( x => x );
csvContent = d3.csvFormat(csvDimension.top(Infinity), [field, field2, ...]);
As Gordon said, csvDimension must be a new dimension in order for the filters to be applied.

Suriem
- 119
- 2
- 5
-
Typescript will complain about type and returning true worked without errors `csvDimension = cf.dimension( x => true );` – David Douglas Apr 30 '20 at 17:36