question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dataTable should probably not use .top(), .bottom()

See original GitHub issue

Hi, I’m trying to implement data table(car model name and speed) and select menu (Day- monday and so). Link to the demo site my json data here is my code for data table

var car =  dc.dataTable('#car')
                .dimension(carGrpdDim)
                .group(function (d){ return 'Modal | Speed'})
                .columns([function (d) { return d.key },  function (d) { return d.value.total }])
                .sortBy(function (d) { return d.value.total })
                .order(d3.descending)
                .size(5)

select menu code

var day = dc.selectMenu('#day')
            .dimension(dayDim)
            .group(dayGrp)
            .controlsUseVisibility(true)
                .promptText('Day');
            day.title(function (d) {
                return d.key;
            });

i want to show only top 5 cars for the day. So i added size(5) but I’m getting cars with speed 0. Though I have cars with speed greater than 0.

Thanks. expected

reality

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gordonwoodhullcommented, Jun 22, 2018

Thanks for including a reproducible example! The issue here is that the data table uses dimension.top(N) to determine which rows to show when dataTable.size() is enabled.

Since you are using a group for your dimension, that resolves to group.top(N), which

Returns a new array containing the top k groups, according to the group order of the associated reduce value. The returned array is in descending order by reduce value.

The “group order” is determined by group.order(f), and by default that attempts to use the reduced values directly for ordering. This won’t work in your case because the reduced values are objects. I guess this somehow results in a no-op, so you get the first five in alphabetical ordering based on the key.

You can fix your example by specifying group.order():

       carGrpdDim.order(v => v.total);

Demo fiddle: https://jsfiddle.net/gordonwoodhull/cbyktand/10/

The use of .top() is documented quite a few places in the dataTable documentation, however it’s pretty confusing. I don’t think it would be a huge performance hit to just take top(Infinity), then sort and cap, as we are already doing in the capped charts (pie, row) per #934.

I’ll retitle this issue accordingly. It’s a little tricky to do in a backward compatible way, but we mostly succeeded for the capped charts.

1reaction
vikkyacommented, Jun 25, 2018

Thanks @gordonwoodhull . It solved the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataTable paging at top and bottom of table
I managed to add the paging control at the top and bottom of the table by specifying to dom option.
Read more >
top and bottom controls on a single table — DataTables forums
Hi guys, Yes, this is something which crops up relatively frequently. The reason it doesn't currently work completely is that DataTables ...
Read more >
DOM positioning - DataTables example
In the example below, the table information is moved to the top of the table, and all the interaction elements to the bottom,...
Read more >
How to fix a row with sorting enabled — DataTables forums
Hi Im looking for a way to allow sorting but keep the first data row FIXED at top. See green row in image....
Read more >
Datatables table loads twice, first time without table data
Or it could be that one of those is when you redeclare oTable as datatable. Not 100% sure, but certainly there is redundancy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found