is ".getChart().getSelection()[0].row" the correct way to get a row from a StringFilter table?

489 views
Skip to first unread message

tracy love

unread,
Jun 25, 2011, 12:59:22 PM6/25/11
to google-visua...@googlegroups.com
ok im stumped, i thought this was working and now its not, may be it never worked.

is ".getChart().getSelection()[0].row" the correct way to get a row from a StringFilter table?


here is a short example that i reworked from the visualization playground..

http://map.region3dfg.org.s3.amazonaws.com/gadget/test22.html    (its also attached)

i want to retrieve the row from the underlying data in the table in the chartwrapper and i want to use StringFilter as well. Click on the row with "john" in it and you get an alert that says "row 3" then apply a string filter "j" and click on "john" and now you get "row 0". i want to get row 3 even after i apply a filter.


test22.html

tracy love

unread,
Jun 25, 2011, 1:43:31 PM6/25/11
to google-visua...@googlegroups.com
the more i look at this the more i am thinking something is broken, as in a bug
so from..

http://code.google.com/apis/chart/interactive/docs/gallery/table.html#Methods

"The row indexes in the selection object refer to the original data table regardless of any user interaction (sort, paging, etc.)."

yeah but thats not what happens when you do a StringFilter

ChartALot

unread,
Jun 26, 2011, 9:18:38 AM6/26/11
to google-visua...@googlegroups.com
Hi,
The function you are looking for is DataView.getTableRowIndex(), which traces the row back to the datatable (the visualization gets a view of the datatable).

Here is a modified selection handler:
     function selectHandler() {
  var selection = table.getChart().getSelection();
         if (selection.length > 0) {
           var rowAtVisualization = selection[0].row;
           var originalRow = table.getDataTable().getTableRowIndex(rowAtVisualization);
           alert("Row "+originalRow);
}
      }

There is another issue that needs a bit of a workaround - the table visualization maintains the selected rows even when the data is changed. This does not really make sense on your scenario. To avoid this behavior you can reset the selection after each redraw:

 google.visualization.events.addListener(table, 'ready', function () {
            table.getChart().setSelection([]);
          });

HTH.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/KO6QsA80QY8J.

To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

tracy love

unread,
Jun 26, 2011, 4:16:57 PM6/26/11
to google-visua...@googlegroups.com
great i cleaned my final up a bit

http://map.region3dfg.org.s3.amazonaws.com/gadget/R3G_browsecolumns_2.html

some of the interaction still isnt exactly corrrect but i think i am good for now
thanks!

p.s. please tell me if you see something else to fix or if i need to reorg to make it more better.
Reply all
Reply to author
Forward
0 new messages