copy
Copy table data to clipboard button.
Please note - this property requires the Buttons extension for DataTables.
Description
This button type serves as a proxy that will automatically detect if the copyHtml5
button can be used based on the browser's capabilities and the libraries available on the page.
This is provided as there is no API in HTML5 that allows a copy to clipboard action when clicking a button.
If the requirements of the copyHtml5
button are not satisfied, no button will be presented to the end user. For the requirements of each button type, please refer to its own documentation.
Options
This button can have the following options set in its configuration object to customise its actions and display, in addition to those options which are available for all buttons (e.g. buttons.buttons.text
):
action
- Type:
function
- Default: Unset
Display a dialogue box that the user can use to copy table data to clipboard
className
- Type:
string
- Default:
buttons-copy
The button's class name. See buttons.buttons.className
for details.
copySuccess
- Type:
boolean
- Default:
true
- Since: 3.1.2
Indicate if the message should be displayed or not when the copy is complete.
customize
- Type:
function
- Default:
undefined
- Since: 1.1.1
Function that can be used to modify the contents of the exported data. The function takes two parameters, the data as configured by the button and the button's configuration object. The value that the function returns is the value that will be used for the export.
This can be particularly useful if you wish to add a company header or footer, description data or any other information to the exported data.
As of Buttons 1.5.2 this function is passed three parameters:
- The data to be copied as a string
- The button configuration object
- A DataTables API instance for the table the button belongs to.
exportOptions
- Type:
object
- Default:
{}
Select the data to be gathered from the DataTable for export. This includes options for which columns, rows, ordering and search. Please see the buttons.exportData()
method for full details - the object given by this parameter is passed directly into that action to gather the required data.
fieldBoundary
- Type:
string
- Default: ``
The character(s) used to enclose each field in the plain text representation of the table that is copied to the system's clipboard. This is automatically added at the start and end of each cell's data.
fieldSeparator
- Type:
string
- Default:
\t
The character(s) used to separate fields in the plain text representation of the table that is copied to the system's clipboard.
footer
- Type:
boolean
- Default:
false
Indicate if the table footer should be included in the exported data or not.
header
- Type:
boolean
- Default:
true
Indicate if the table header should be included in the exported data or not.
messageBottom
Message to be shown at the bottom of the table, or the caption
tag if displayed at the bottom of the table.
messageTop
Message to be shown at the top of the table, or the caption
tag if displayed at the top of the table.
newline
- Type:
string
- Default:
\n
The character(s) used to separate the lines of data. Please note that on Windows client's the default is \r\n
. All other platforms have a default or \n
only.
text
- Type:
string
- Default:
Copy
The button's display text. The text can be configured using this option (see buttons.buttons.text
) or the buttons.copy
option of the DataTables language
object.
title
Title of the table that will be included in the exported data. Please see buttons.exportInfo()
for all options relating to this parameter.
Examples
DataTables initialisation: Use the copy
button type to alias the HTML button options.:
new DataTable('#myTable', {
layout: {
topStart: {
buttons: ['copy']
}
}
});
DataTables initialisation: Use the exportOptions
to copy only the current DataTable page:
new DataTable('#myTable', {
layout: {
topStart: {
buttons: [
{
extend: 'copy',
text: 'Copy current page',
exportOptions: {
modifier: {
page: 'current'
}
}
}
]
}
}
});