Copy button behavior interrupted when using action option
Copy button behavior interrupted when using action option
I am adding the copyHtml5 button to my table, and it all works great until I add the "action" option to my configuration. My goal here is to override the default confirmation message with my own which gets positioned in a shared message container used by my application. Here is the button configuration.
buttons: [{
text: 'Copy Table',
extend: 'copyHtml5',
exportOptions: {
columns: ':visible',
format: {
body: function(innerHtml, col, row) {
var data = oTable.cell(row, col+':visible').data();
data = data === null ? '' : data;
return data;
}
}
},
action: function(e, dt, node, config) {
var row_count = dt.rows().count();
$.setStateMessage('Copied ' + row_count + ' rows to the clipboard', 'green');
}
}],
Again, without the action, the copy function works perfectly. With the action, the custom message is displayed, but nothing is copied to the clipboard. Just the presence of the action with no code inside the function causes the copy to break. Does anyone know why this might be happening? I am using DataTable 1.10.11 and Buttons 1.1.2. Thanks.
Answers
Yup - that is expected. You are replacing the default action, which is to copy to the clipboard, with your own function!
Two options:
$.fn.dataTable.ext.buttons.copyHtml5.action( e, dt, node, config );
Allan