Table visualization - set selected row, ensure row is shown

229 views
Skip to first unread message

newb

unread,
Dec 12, 2016, 4:31:02 PM12/12/16
to Google Visualization API
Hi,

I've loaded a Table that has enough rows that it creates a scroll bar.   I'd like to programmatically set one row to appear selected, and I'd like to do something to make sure the selected row is being shown by the Table. 

I know enough to keep my column null, like this:

gGoogleTable.setSelection('[{row: 100, column:null}]');

I've tried it before the draw:

gGoogleTable = new google.visualization.Table(document.getElementById('table_div'));
gGoogleTable.setSelection('[{row: 100, column:null}]');
gGoogleTable.draw(gGoogleData, {width: '100%', height: '200px'});
google.visualization.events.addListener(gGoogleTable, 'select', selectionChangedTable);

I've tried it after the draw:

gGoogleTable = new google.visualization.Table(document.getElementById('table_div'));
gGoogleTable.draw(gGoogleData, {width: '100%', height: '200px'});
google.visualization.events.addListener(gGoogleTable, 'select', selectionChangedTable);
gGoogleTable.setSelection('[{row: 100, column:null}]');

No console errors but no joy either.   Any suggestions?

Daniel LaLiberte

unread,
Dec 12, 2016, 5:00:48 PM12/12/16
to Google Visualization API
Hi Dave,

Your argument to setSelection is a string, but it would need to be an array to work at all.  And you should be able to leave off the column property.  So try this:

gGoogleTable.setSelection([{row: 100}]);

Also, the draw() call is not necessarily done drawing immediately after you call it, so you would have to wait for the 'ready' event before you could safely make any difference there.  

But having said all that, I still wasn't sure this actually worked since I haven't tested it, so here is a demo:  https://jsfiddle.net/dlaliberte/zr216csr/


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/cb2dc2ac-62b5-4860-901a-02432f563fe1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

newb

unread,
Dec 12, 2016, 5:33:25 PM12/12/16
to Google Visualization API
Oh, geez, that was helpful.   Thanks Daniel.
To post to this group, send email to google-visua...@googlegroups.com.



--
Reply all
Reply to author
Forward
0 new messages