Help getting button label on-click in collection drop down

Help getting button label on-click in collection drop down

chboccachbocca Posts: 20Questions: 3Answers: 0

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:

Answers

  • allanallan Posts: 48,322Questions: 1Answers: 6,976 Site admin
    Answer ✓

    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

  • chboccachbocca Posts: 20Questions: 3Answers: 0

    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.

  • allanallan Posts: 48,322Questions: 1Answers: 6,976 Site admin
    Answer ✓

    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

  • chboccachbocca Posts: 20Questions: 3Answers: 0

    Ha! Yes it does ...

    here's working demo.

    Thank you Alan!

    c

  • chboccachbocca Posts: 20Questions: 3Answers: 0

    Updated working demo address. c

  • allanallan Posts: 48,322Questions: 1Answers: 6,976 Site admin

    Nice one - thanks!

    Allan

Sign In or Register to comment.