How to disable the success message window of copy button action?

How to disable the success message window of copy button action?

chocchoc Posts: 95Questions: 11Answers: 8

Link to test case: https://live.datatables.net/kuqoqoce/1/watch?html,css,js,output
Description of problem:

I wonder how to elegantly disable the pop-up window on a successfully copied message?
I couldn't find any documentation on this and have to hide the window in a hack way with css.

I'm in transitioning to DT2.0, so I'm still using dom to set the layout for customization, and I've already done it for exporting excel and csv. But the pop-up window after copying became a problem for me.

Below is what I want to acheive with Tailwind integration:

I would like to have only the successful icon after copying instead of the pop-up window.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    There is no option in the code to disable the popover message at the moment. I'd welcome a pull request that adds an option to the button which adds that ability though. Perhaps it could switch on if buttons.copySuccess is an empty string? No point in showing the model at that point!

    Allan

  • chocchoc Posts: 95Questions: 11Answers: 8
    edited August 8

    Thank you allan.

    While I add the option to control it, I found it easier to implement by just adding an additional option, for example 'copySuccess' (or other names):

                    buttons: [
                        {
                            extend: 'copyHtml5',
                            copySuccess: false,
                            action: function (e, dt, node, config) {...}
                        }
    

    and then in the source code:
    https://github.com/DataTables/Buttons/blob/c863eed3dcf6200ffa23f4917d4eda0c35fc03e4/js/buttons.html5.js#L918

    change it to:

                    if (successful) {
                        if (config.copySuccess !== false) {
                            dt.buttons.info(
                                dt.i18n('buttons.copyTitle', 'Copy to clipboard'),
                                dt.i18n(
                                    'buttons.copySuccess',
                                    {
                                        1: 'Copied one row to clipboard',
                                        _: 'Copied %d rows to clipboard'
                                    },
                                    exportData.rows
                                ),
                                2000
                            );
                        }
    
                        cb();
                        return;
                    }
    

    will work. What do you say?

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    I think that is fair, yes. If you send a PR with that change, I'll get it merged in :)

    Allan

  • chocchoc Posts: 95Questions: 11Answers: 8
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    And merged - thanks for your contribution!

Sign In or Register to comment.