-->

dc datatable without grouping the rows

2019-04-25 00:52发布

问题:

Is it possible to have a dc data table without showing the data in groups? I just want to show all the data across all groups!

My code is as follows:

dc.dataTable(".dc-data-table")
  .dimension(dateDimension)
  .group(function (d) {
    return ''
  })
  .size(10) // (optional) max number of records to be shown, :default = 25
  .columns([
      function (d) {
          return getFormattedDate(d.dd);
      },
      function (d) {
          return d.referredfor;
      },
      function (d) {
          return numberFormat(d.cost);
      },
      function (d) {
          return d.gender;
      }
  ])
  .sortBy(function (d) {
      return d.dd;
  })
  .order(d3.ascending)
  .renderlet(function (table) {
      table.selectAll(".dc-table-group").classed("info", true);
  });

This shows my data table but with an empty row like so:

回答1:

It doesn't look like there is currently a way to do this. Sounds like a reasonable request! You might submit an enhancement request, or even better, a PR.

Here is the relevant code, in renderGroups:

https://github.com/dc-js/dc.js/blob/master/src/data-table.js#L121

It is nesting the data by key and then adding a table row for each group. It would be trivial to disable this, but the problem is that later, renderRows selects those "group rows" in order to add data under them:

https://github.com/dc-js/dc.js/blob/master/src/data-table.js#L156

EDIT: it's an option, .showGroups(), as of 2.0 beta 16



回答2:

A simple workaround:

You can override the corresponding css class to avoid display of that row, by using:

<style>
  .dc-table-group{display:none}
</style>

in your html.