Hello everyone,
I would like to add a button to a table header. I accomplished this by using the following
String columnID = "Test";
table.setColumnHeader(columnID, "<input type='button' id='headerButton' onClick='myJSFunction(event)'/>" + columnID);
This is pretty much what is advised in this thread (
https://vaadin.com/forum/#!/thread/774477/8020605
).
However, the problem is that I also want this table to be sortable if the user clicks on a header. So
“clicking the header panel”
and
“clicking the button inside the header panel”
should
do two different things
. Common sense would tell me that the browser receives the click event on the header button (i.e. innermost HTML element) and then propagates (“bubbles”) the event upwards the HTML DOM tree to the table header panel. So I tried to disable the event bubbling:
(this is client-side javascript)
function myJSFunction(event){
if(!event){
// Internet Explorer 8 and lower
event = window.event;
}
if(event.stopPropagation){
// Internet Explorer 9 & other browsers
event.stopPropagation();
}else{
// Internet Explorer 8 and lower
event.cancelBubble = true;
}
// actual event processing for the button goes here
}
The Firefox debugger tells me that the “myJSFunction(…)” is called correctly upon button click. However, no matter what I do, the table ALWAYS gets sorted! I tried returning “false” in the “onClick” attribute and in the event handler function, but to no avail.
.
I’d be grateful for any advice.
Martin