Select Handler not working

105 views
Skip to first unread message

Paul Shallis

unread,
May 7, 2021, 4:33:17 AM5/7/21
to Google Visualization API
I'm hoping this is a problem that's really easy to fix. Having copied all of the necessary code from the Google Visualization site, everything is working with one exception. I have a data table where, if I select a row, the select handler is called - but I am unable to get table.getSelection() to work 

I've seen a suggestion that I might need to include getChart(), but that doesn't fix it.

In the extract below, I get the first alert message when selecting a row, but not the second, and the code stops running at that point.

Can anyone suggest what the problem might be?

Many thanks!


<html>

</body>

<head>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawTable_1);

function drawTable_1() {

js_booking = <?php echo json_encode($arr_booking); ?>;
js_name = <?php echo json_encode($arr_name); ?>;

var data = new google.visualization.DataTable();
data.addColumn('string', 'Booking');

data.addColumn('string', 'Name');

for (i = 0; i < 5; i++) {

data.addRows([
[js_booking[i], js_name[i]]
]);

}

var table = new google.visualization.Table(document.getElementById('table_div_1'));

table.draw(data, {showRowNumber: false, sort: 'disable', width: '95%', allowHtml:true});

google.visualization.events.addListener(table, 'select', selectHandler);
}

function selectHandler(e) {

alert('A table row was selected');

var selection = table.getSelection();

alert('Selection identified');

}

</script>

</head>
<body>
<div id="table_div_1">Loading...</div>
</body>

<br>

</html>

Simone Fracassa

unread,
May 17, 2021, 4:33:36 AM5/17/21
to Google Visualization API
Same problem here, it seemes the getSelection() suddenly stopped to return the selection. It have always worked, I use it since years. :(

Did you managed to solve the issue?

Simone Fracassa

unread,
May 17, 2021, 4:37:45 AM5/17/21
to Google Visualization API
I temporarily solved by loading the previous version of libraries (49).

Paul

unread,
May 18, 2021, 6:43:10 AM5/18/21
to Google Visualization API
Thanks Simone, but this hasn't helped me unfortunately. I tried using earlier versions, but it didn't fix the problem. I'm still finding that the line "var selection = table.getSelection();" stops the javascript running for some unknown reason.
Reply all
Reply to author
Forward
0 new messages