1

I am clicking a button to copy to the clipboard, a return of rows depending if a string ('star') is present. However, when the number of rows returned are 0, the popup window says "Copied one row to clipboard." And when I try to paste, it pastes the previously saved clipboard, which can cause confusion. What I would want is to have the clipboard erased if no rows are returned.

Is there a condition I can add so that the clipboard is erased if there are no rows returned? If not, are there any alternative practical solutions?

{
  extend: 'copyHtml5',
  text: 'Copy Star',
  header: false,
  title: null,
  className: 'copy-star',
  newline: ', ',
  exportOptions: {
    rows: function(idx, data, node) {
      return (!data[8].toLowerCase().includes('star')) ? true : false;
    },
    columns: [0]
  }
},
andrewJames
  • 19,570
  • 8
  • 19
  • 51
Robert
  • 9
  • 1
  • I am not able to reproduce your issue where "_when the number of rows returned are 0, the popup window says "Copied one row to clipboard."_". The message says "Copied 0 rows..." for me. So, we would need a [mre] for that, to make it easier to help you. – andrewJames Jun 25 '21 at 13:45
  • Regarding clearing the clipboard if no rows are copied, you can take a look at the guidance here [Interact with the clipboard](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard) - but note it may not be fully implemented in all browsers. Also, there are various existing questions on SO such as [this](https://stackoverflow.com/questions/16748735/clear-clipboard-to-prohibit-unauthorised-copying-insert-message) and others. – andrewJames Jun 25 '21 at 13:45
  • Hmm, yes that's weird. I was able to utilize an HTML/CSS/JS simulator and in there, it did show "Copied 0 rows". However, the problem still remains, it doesn't copy 0 rows, rather the clipboard never got overwritten. I did visit [interact with the clipboard](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard) and I saw Clipboard API's Clipboard.writeText() and Clipboard.write() function. But where should I place that in my code? – Robert Jul 14 '21 at 03:12
  • You would place such code (and the code to select the table's data) in the action function of a custom button: `buttons: [ { text: 'Custom Copy', action: function ( e, dt, node, config ) { ... } } ]`. But it would be better if you can provide a [mre] for your original problem. – andrewJames Jul 14 '21 at 12:56

0 Answers0