Some doubts about Buttons extension

Some doubts about Buttons extension

alesnavalesnav Posts: 19Questions: 5Answers: 1
edited April 2016 in Free community support

Hello there!

I have some doubts related to Buttons extension. I am trying to migrate everything coded using TableTools but I'm having some problems...

In TableTools there were two options that I can't find in Buttons:

1.- Buttons ToolTip. I can't remember if I added this option manually, but I'm sure it was available for Print button. This adds a tooltip to the button, using HTML Title property. Does this exist in Buttons extension?

2.- fnRowSelected and fnRowDeselected. These two functions were available from defaults TableTools options
( $.extend(true, $.fn.dataTable.TableTools.defaults, { 'fnRowSelected': function ( nodes ) { ... } } ) but now the only docs related to these functions are https://datatables.net/reference/event/select and https://datatables.net/reference/event/deselect . How can I set defaults for both?

3.- Buttons actions only over visible columns. In TableTools there is an option for this, but I can't find the option in Buttons/Select. For example, if I click "Copy" button when only one row is selected, I want to copy only that one row, not the whole table.

Thanks,
Best regards

Answers

  • rink_attendant_6rink_attendant_6 Posts: 16Questions: 4Answers: 1
    Answer ✓

    Tooltips can be added using the titleAttr property of the button in the buttons array.

    Actions over only visible columns can be specified using the exportOptions property of the button.

    I think you are looking for something like:

    buttons: [
        {
            titleAttr: 'Tooltip text here',
            exportOptions: {
                columns: ':visible'
            }
        }
    ]
    

    (along with other properties of your button, and other buttons, if any)

    As for your second question I don't know.

  • allanallan Posts: 61,985Questions: 1Answers: 10,162 Site admin
    Answer ✓

    2.- fnRowSelected and fnRowDeselected

    There is no longer a callback option for these actions - you need to use events. If you need to assign a default action you could listen for the init event and then attach the select and deselect events to the newly initialised table as you require.

    Allan

  • alesnavalesnav Posts: 19Questions: 5Answers: 1
    edited April 2016

    What a quickly response!! Thanks!!

    So, I have this:

            {
                titleAttr: 'ToolTip',
                exportOptions: {
                    columns: ':visible',
                    modifier: {
                        selected: true
                    }
            }
    

    With this, I have questions 1 and 3 solved.

    My problem comes with option 2. Allan, I think your idea sounds very good, but I am not able to get it done :(

    I tried with initComplete without success:

    $.extend(true, $.fn.dataTable.defaults, {
        initComplete: function() {
            this
                .on( 'select', rowSelectedFunction )
                .on( 'deselect', rowDeselectedFunction );
        },
    

    Maybe I don't know what to put instead of this... Any idea?

  • allanallan Posts: 61,985Questions: 1Answers: 10,162 Site admin
    Answer ✓

    I would be surprised if that wasn't giving a Javascript error is it not? this does not have an on() method in initComplete.

    Try using this.api().on( ... );

    Allan

  • allanallan Posts: 61,985Questions: 1Answers: 10,162 Site admin
    Answer ✓

    Oh - and note that if you use initComplete in your configuration options it would overwrite the default.

  • alesnavalesnav Posts: 19Questions: 5Answers: 1

    Nice, everything works now.

    Thanks!!!

This discussion has been closed.