scott_trinh
scott_trinh

Reputation: 165

How can you do grouping in dc.js datatables?

Sample Data:

[
  { 'date': new Date(2014,03,12,0).getTime(), 'value': 1 },
  { 'date': new Date(2014,03,12,12).getTime(), 'value': 2}
]

I am loading this sort of data into dc.js, and doing some clever transformations to return dimensions that have the date key set to the beginning of the day (or month, or year, etc.) and then in the charts, I am reduceSuming the dataset, it works like a charm! I can reduce each days data into a total, or month, or quarter, etc. However, when I try to do the same thing in the dataTable, no dice, since it doesn't use real crossfilter groups, and it doesn't collapse the data into reductions like the charts can. Am I missing something, or am I just trying to get dataTables to do something they were not meant to do? I can use another tabling creation technique, but I thought maybe someone had figured out how to do it in dc.

Thanks!

Upvotes: 0

Views: 796

Answers (1)

scott_trinh
scott_trinh

Reputation: 165

If I would have looked just a little bit harder, I would have found this! Works well enough for now. Basically, you make a "fake" dimension using your desired group, giving it a .top() method that returns an object that represents your grouped data. Read the google group post for more details!

Upvotes: 2

Related Questions