Help getting button label on-click in collection drop down
Help getting button label on-click in collection drop down
Any ideas on what 'className' to specify in jQuery on-click function to get button labels inside colvis or custom collection?
I've tried: '.dt-button', '.dt-button-collection', etc.
Does main page buttons great, but can't trigger for buttons in ui-widget menu.
Thanks in advance!
Here's code in demo:
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print', 'colvis',
{ extend: 'collection',
className: 'myCollection',
text: 'Collection',
buttons: [
{ text: 'Button 1' },
{ text: 'Button 2' },
{ extend: 'columnToggle',
text: 'Button 3',
columns: '.position'},
],
},
],
} );
$('.dt-button').on( 'click', function ( htmlElement ) {
var label = $( this ).text();
alert(label);
} );
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You wouldn't use a jQuery click event handler to handle a button click at all. You would use a custom action function:
buttons.buttons.action
.Allan
OK, yes, understand. Thank you Allan. Right, I don't see why you would need this capability 'cause you can do inside dt. But, was curious about why I could not get the jQuery click event to work for the drop down button menus.
I think if you used
$('body').on( 'click', '.dt-button', function ( htmlElement ) {
it probably would work. I suspect its just that the.dt-button
selector wasn't matching anything at the point it was running.Allan
Ha! Yes it does ...
here's working demo.
Thank you Alan!
c
Updated working demo address. c
Nice one - thanks!
Allan