Fully customizing output of copyHtml5 using exportOptions format
Fully customizing output of copyHtml5 using exportOptions format

I'm trying to build an copy to clipboard feature that formats the output in a certain way where it doesn't get affected by the current column visibility/order (but does print just rows that are visible now according to the current filter settings)
I thought of using the format and header/body to completely customize the return value, but it seems that data that can be accessed from within the function (data, row, column, node)
is limited, and also that the function runs each for every column cell.
Below is an example I tried... column3header / column3data would be where the appropriate data gets inserted (I couldn't figure out how to fetch appropriate attributes from columns_params)
{
extend: 'copyHtml5',
text: 'Copy to Clipboard',
messageTop: '',
messageBottom: '',
fieldBoundary: '',
fieldSeparator: '',
exportOptions: {
format: {
header: function (data, row, column, node) {
var output = column3header + '/' + column1header + '/' + column2header;
return output;
},
body: function (data, row, column, node) {
var output = column3data + '/' + column1data + '/' + column2data;
return output;
}
},
columns: ':visible'
},
title: ""
}
Does anyone have a suggestion of ways I could achieve what I'm trying to do?
Answers
I'm not clear what you want to customize. Take a look at the customize option of the
copyHtml5
button. See an example of this using the print button here. The first parameter for thecopyHTML
customize function is the "The data to be copied as a string".Kevin
To give you more exact context — I'm trying to build a 'copy to clipboard' button that prints out the contents of the table converted to a 'wiki' syntax instead of the default HTML syntax.
If my data goes:
The output should become:
I've managed to customize the opening head/enclosing foot syntax using
And since the header will most likely be the same every time, I did this:
Then the problem goes for customizing the body.
I understand that whatever mechanisms I put into the
function (data, row, column, node)
gets applied to the data, but I see that it runs sequentially for all columns from start to finish. So if I want to switch around column order (only for clipboard export) and merge, I'll need some way to access data from 'outside' because when the body function runs it only has access to the current node.There have been som e recent changes to how the order of the exported columns is handled. See if this thread helps and does what you want.
Kevin
Unfortunately the thread you linked to doesn't seem to be entirely related to my issue here.
Any way could I access the DataTables
api()
from within the body function?I figured out a way myself, ended up manually getting the entire DataTable then finding the row I want using the
node
provided from within, then finding the columns I need.let rowData = $('#table').DataTable().row(node).data();
Sorry I haven't been much help. I'm not sure what you mean by column order, etc. Sounds like you have your issue resolved. Maybe creating a custom button, like this example would make it easier to customize the output. You will need to use Javascript to copy to the clipboard, maybe something like this.
Kevin