Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distinction between a DataTable and a DataView #270

Closed
orwant opened this issue May 9, 2015 · 5 comments
Closed

distinction between a DataTable and a DataView #270

orwant opened this issue May 9, 2015 · 5 comments

Comments

@orwant
Copy link
Collaborator

orwant commented May 9, 2015

What would you like to see us add to this API?
The distinction between a DataTable and a DataView is poor.  If I update 
Cell values in a DataTable and refilter the DataView, I would expect the 
data to be updated.  This works ok if you never edit the data in the 
datatable with other Javascript functions, but if you edit it with 
Javascript functions and then do the refilter (or even create a new 
dataview each time), the updated cell values are not there. The filter 
works on the new data, but the values shown are still the old values.  
Without this functionality I do not find the DataTable/DataView classes 
very useful.  

This may be a bug.  So here is the code snippet.  
    if (typeof(datatable)=='undefined'){
                //only define the datatable once.  
        datatable = new google.visualization.DataTable();
                //load all of the data once.  
        }

        //update specific cells in the datatable.  

        //every time after the datatable values have been updated run this 
code.  
    var dataview = new google.visualization.DataView(datatable);    

    //the view updates the filtered rows based on the new data, but 
doesnt show the updated values.  why??
    dataview.setColumns([3, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20]);
    dataview.setRows(dataview.getFilteredRows([{column: 4, maxValue: 
400}]));
    var visualtable = new google.visualization.Table
(document.getElementById('mainsection'));
    visualtable.draw(dataview, {sortColumn: 4});


What component is this issue related to (PieChart, LineChart, DataTable,
Query, etc)?
DataTable/DataView

*********************************************************
For developers viewing this issue: please click the 'star' icon to be
notified of future changes, and to let us know how many of you are
interested in seeing it resolved.
*********************************************************

Original issue reported on code.google.com by devinjacobson on 2010-05-01 16:07:53

@orwant
Copy link
Collaborator Author

orwant commented May 9, 2015

I find the example here to be somewhat complex.  (Should "dataview.getFilteredRows()"
be "datatable.getFilteredRows()"?)  When I try a simpler example, the view is updated
when I update the table:

      google.load('visualization', '1', {packages:['table']});
      google.setOnLoadCallback(drawTable);
      var view;
      var data;
      var table;

      function drawTable() {
        data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('number', 'Salary');
        data.addRows(2);
        data.setCell(0, 0, 'Mike');
        data.setCell(0, 1, 10000, '$10,000');
        data.setCell(1, 0, 'Jim');
        data.setCell(1, 1, 8000, '$8,000');

        table = new google.visualization.Table(document.getElementById('table_div'));
        view = new google.visualization.DataView(data);
        view.setColumns([1]);
        table.draw(view, {showRowNumber: true});
      }

      function update() { 
        data.setCell(1, 1, 4000, '$4,000');
        table.draw(view, {showRowNumber: true});
      }

here, when update() gets called, the table visualization is updated even though it's
being drawn from the view and not the table.

Original issue reported on code.google.com by dglibicki@google.com on 2010-05-03 12:14:03

@orwant
Copy link
Collaborator Author

orwant commented May 9, 2015

Thanks, 
I see what is different between what you are doing and what I am doing.  I did not
add the formattedValue variable (the fourth parameter in setCell).  Apparently this
is what I need.  Doesn't make much sense why I would need this.  But I have adjusted
the code to include this parameter on the setCell function and it works as I expect.
 If you have some time, you may want to look at it.  If you run your code without the
4th parameter, I imagine you will see the same thing I saw.  That it doesnt update.


Anyway thanks, I can use these classes now.  
Devin

Original issue reported on code.google.com by devinjacobson on 2010-05-04 02:36:07

@orwant
Copy link
Collaborator Author

orwant commented May 9, 2015

If you never call setCell() with the fourth parameter, the code also works fine.  The
problem occurs if you call setCell() with four parameters and then call it again with
three.  What happens in that case is that the value is overwritten but the formatted
value is not overwritten, so when the Table visualization is redrawn, it appears as
if nothing has changed.

This has nothing to do with DataView.  The same thing would happen if you would use
the DataTable directly.

Original issue reported on code.google.com by dglibicki@google.com on 2010-05-04 07:56:22

@orwant
Copy link
Collaborator Author

orwant commented May 9, 2015

(No text was entered with this change)

Original issue reported on code.google.com by daniel.libicki on 2010-05-04 07:58:05

@orwant
Copy link
Collaborator Author

orwant commented May 9, 2015

Yes, this is correct.  But if someone uses a formatter and never calls setCell with
a
fourth parameter, this happens as well.  This is what was happening for me.  I dont
know what the code is like or if it makes sense to fix, but from a users perspective,
this creates a confusing situation.  

Original issue reported on code.google.com by devinjacobson on 2010-05-04 10:06:25

@orwant orwant closed this as completed May 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant