select and sort events run even if I define my own functions

30 views
Skip to first unread message

Robert Mason

unread,
Jan 22, 2016, 1:59:26 PM1/22/16
to Google Visualization API
I am having a bit of an issue, If I add event functions for select and sort on my table the default Google functions run anyway. It's kind of hard to explain, but here is a very simple example...

var chart = new google.visualization.Table(document.getElementById('myTable'));
google
.visualization.events.addListener(chart, 'sort', function(e) { handleSort(e, chart); });
chart
.draw(opts, dataTable);


function handleSort(e, chart) {
   
if(e.column == 9) {
        console
.log('inside sort function');
       
return false;
   
}
}


With that code above, when I click on the header for column 9 I get the console log of 'inside sort function', but then the table sorts itself on that column. I have even tried doing this...

function handleSort(e, chart) {
   
if(e.column == 9) {
        chart
.options['sortColumn'] = 0;
        chart
.options['isAscending'] = true;
   
}
}


When that runs, it still sorts the table by column 9. No matter what I do I can't get the table to stop sorting. I did set 'sort'  to 'event' in the opts object that gets passed in to the draw method.

Please, I am pretty desperate for ideas or answers. I need to make the table stop sorting when column 9 is clicked on. The reason... there is a button in the header for column 9, when the user clicks that button it is supposed to do an action, which is does, but it sorts the table which ruins everything. Thank you in advance for any help, I appreciate all input.

Daniel LaLiberte

unread,
Jan 22, 2016, 2:24:20 PM1/22/16
to Google Visualization API
Robert,

Setting the 'sort' option to 'event' is necessary, and it should be sufficient to prevent the internal sorting.  But if you are also specifying the initial sortColumn, there might be some interference since it will be used each time the chart is redrawn with chart.draw().  It shouldn't be used for any of the internal redraws that occur, but it is possible you have found a bug.  Try not setting the initial sortColumn to see how that works.

If you can point me at your page, I would be happy to look into what I see it doing.


--
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-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@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/f6d1fcdd-a669-4f2f-8ca4-fbae08999480%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Robert Mason

unread,
Jan 22, 2016, 3:03:39 PM1/22/16
to Google Visualization API
Well, I was able to finally get it working. Seems like removing the initial sortColumn worked, but now I am stuck on a whole new issue that is quite interesting....

I have 2 events bound to the table, sort and select, because I need to disable sort on 2 columns, and I need to enable multi row select. The problem... Apparently if you bind a select event, the sort event never gets called. Instead, when I click on a table header to invoke tableSort, it runs tableSelect. So the select event supersedes the sort event and sort will never get called. Any ideas?


On Friday, January 22, 2016 at 11:24:20 AM UTC-8, Daniel LaLiberte wrote:
Robert,

Setting the 'sort' option to 'event' is necessary, and it should be sufficient to prevent the internal sorting.  But if you are also specifying the initial sortColumn, there might be some interference since it will be used each time the chart is redrawn with chart.draw().  It shouldn't be used for any of the internal redraws that occur, but it is possible you have found a bug.  Try not setting the initial sortColumn to see how that works.

If you can point me at your page, I would be happy to look into what I see it doing.

On Fri, Jan 22, 2016 at 1:59 PM, Robert Mason wrote:
I am having a bit of an issue, If I add event functions for select and sort on my table the default Google functions run anyway. It's kind of hard to explain, but here is a very simple example...

var chart = new google.visualization.Table(document.getElementById('myTable'));
google
.visualization.events.addListener(chart, 'sort', function(e) { handleSort(e, chart); });
chart
.draw(opts, dataTable);


function handleSort(e, chart) {
   
if(e.column == 9) {
        console
.log('inside sort function');
       
return false;
   
}
}


With that code above, when I click on the header for column 9 I get the console log of 'inside sort function', but then the table sorts itself on that column. I have even tried doing this...

function handleSort(e, chart) {
   
if(e.column == 9) {
        chart
.options['sortColumn'] = 0;
        chart
.options['isAscending'] = true;
   
}
}


When that runs, it still sorts the table by column 9. No matter what I do I can't get the table to stop sorting. I did set 'sort'  to 'event' in the opts object that gets passed in to the draw method.

Please, I am pretty desperate for ideas or answers. I need to make the table stop sorting when column 9 is clicked on. The reason... there is a button in the header for column 9, when the user clicks that button it is supposed to do an action, which is does, but it sorts the table which ruins everything. Thank you in advance for any help, I appreciate all input.

--
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.



--

Daniel LaLiberte

unread,
Jan 22, 2016, 3:17:59 PM1/22/16
to Google Visualization API
Sounds plausible that the select event handling overrides the header clicking for sorting.  You might have to interpret the select event when it is over the header and handle it by doing your sorting.

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.



--

--
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-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages