dc.js icon indicating copy to clipboard operation
dc.js copied to clipboard

Ordering Issue in datatable

Open DylanB123 opened this issue 13 years ago • 9 comments

When trying to display an ordered data table, Chrome is giving results in a different a different order than Firefox/IE, and none of them display in descending order.

DylanB123 avatar Oct 11 '13 03:10 DylanB123

@DylanB123 Can you give us an example of the difference?

jrideout avatar Oct 11 '13 13:10 jrideout

Yup, meant to do it earlier. I've just been somewhat swamped. When displaying the data below, Chrome returns it in the the batch_id order of (8,1,3,4,5,6,7,2,9,11,12,13,14,15). Both IE and Firefox are in the correct sequential order. Even added a date field and sorted on that and I got the same order.

This all could be a mistake on my part too. I haven't touched javascript in years.

CSV Data...

batch_id,step1,step2,step3,step4,size
1,6,7,28,10,12
2,6,8,30,10,18
3,6,4,26,4,7
4,5,6,27,7,9
5,6,10,27,10,18
6,7,3,25,7,6
7,6,2,20,2,3
8,6,5,29,7,9
9,7,7,27,8,13
10,23,7,28,8,14
11,8,5,26,6,8
12,8,9,28,12,18
13,7,9,27,11,17
14,6,10,30,10,19
15,6,11,29,14,20

...the javascript I'm using to create the chart...

d3.csv("data/data.csv", function (data) {

    data.forEach(function(d) {

        d.bid = +d.batch_id;
        d.s1 = +d.step1;
        d.s2 = +d.step2;
        d.s3  = +d.step3;
        d.s4 = +d.step4;
        d.sz = +d.size;
        d.elapsed = d.s1 + d.s2 + d.s3 + d.s4;
    });

    var facts = crossfilter(data);
    var batchDim = facts.dimension(function(d) {return d.bid;});    
    var dataTable = dc.dataTable("#dc-table-graph");

    dataTable.width(300)
        .height(300)
        .dimension(batchDim)
        .group(function(d) {return"Batch Table";})
        .size(data.length)
        .columns([
            function(d) { return d.bid; },
            function(d) { return d.s1; },
            function(d) { return d.s2; },
            function(d) { return d.s3; },
            function(d) { return d.s4; },
            function(d) { return d.elapsed; },
            function(d) { return d.sz; }
            ])
        .sortBy(function(d) {return d.bid;})
        .order(d3.ascending);

    dc.renderAll();
});

and the html...

<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>

<title>dc.js Experiment</title>

    <script src='js/d3.v3.js' type='text/javascript'></script>
    <script src='js/crossfilter.js' type='text/javascript'></script>
    <script src='js/dc.js' type='text/javascript'></script>
    <script src='js/jquery-1.10.2.js' type='text/javascript'></script>
    <script src='js/bootstrap.js' type='text/javascript'></script>

    <link href='css/bootstrap.css' rel='stylesheet' type='text/css'>
    <link href='css/dc.css' rel='stylesheet' type='text/css'>

</head>
<body>
    <div class='container' style='font: 12px sans-serif;'>      
        <div class='row'>
            <div class='span12' style="overflow: auto">
                <table class='table table-hover table-condensed' id='dc-table-graph' overflow='scroll'>
                    <thead>
                        <tr class='header'>
                            <th>Batch ID</th>
                            <th>Step 1</th>
                            <th>Step 2</th>
                            <th>Step 3</th>
                            <th>Step 4</th>
                            <th>Elapsed Min</th>
                            <th>Size</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>      
    </div>
    <script src='simple_vis.js' type='text/javascript'></script>
</body>
</html>

DylanB123 avatar Oct 12 '13 04:10 DylanB123

I think It is related to ECMA script rule where other browsers works ok with true false but chrome need -1,0,1 as return value.

see: http://stackoverflow.com/questions/1969145/sorting-javascript-array-with-chrome. (above example is object but gives similar behavior )

I have reproduced the same output in chrome and it is related to crossfilter not dc.js as crossfilter provide the sort functions

gauravmeena0708 avatar Nov 07 '13 12:11 gauravmeena0708

I have slightly changed how the nested sorting is done on master to address another sorting related issue; not sure if it also fixes this problem.

Nick

On Thu, Nov 7, 2013 at 7:37 AM, Gaurav Meena [email protected]:

I think It is related to ECMA script rule where other browsers works ok with true false but chrome need -1,0,1 as return value.

see: http://stackoverflow.com/questions/1969145/sorting-javascript-array-with-chrome .

I have reproduced the same output in chrome and it is related to crossfilter not dc.js as crossfilter provide the sor functions

— Reply to this email directly or view it on GitHubhttps://github.com/NickQiZhu/dc.js/issues/331#issuecomment-27959013 .

NickQiZhu avatar Nov 08 '13 01:11 NickQiZhu

In master branch the ordering issue in chrome is solved but

order does not change with d3.descending or d3.ascending it remains static.

(and when I try to do sorting by groups it always do string sort but order changes)

gauravmeena0708 avatar Nov 08 '13 06:11 gauravmeena0708

Can you given this a try with your test? It should be fixed by this change.

NickQiZhu avatar Nov 08 '13 15:11 NickQiZhu

yes it is solved thanks

gauravmeena0708 avatar Nov 11 '13 07:11 gauravmeena0708

How to remove grouping from dc.DataTable. After removing it throws error as Mandatory attribute chart.group is missing on chart[#.dc-data-table]

Arpanjainson avatar Oct 07 '14 04:10 Arpanjainson

@Arpanjainson, I think you have a question which is unrelated to the tickets you're posting on, and this sounds like a support question which is better addressed on Stack Overflow or the user group.

gordonwoodhull avatar Oct 07 '14 05:10 gordonwoodhull