csv
Create and save a CSV file that contains the data from the table.
Please note - this property requires the Buttons extension for DataTables.
Description
This button type serves as a proxy that will automatically detect if the csvHtml5
buttons can be used based on the browser's capabilities and the libraries available on the page.
This is provided as an option since the HTML5 button type requires a reasonably modern browser which may not always be available to the end user.
If the requirements of the csvHtml5
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
):
Name | Type | Default |
---|---|---|
action | ||
Create and save a CSV file. | ||
bom Since: 1.2.2 | false | |
Option to include UTF-8 Byte Order Mark ( | ||
charset | null | |
Character set to use in the file export. When | ||
className | buttons-csv buttons-html5 | |
The button's class name. See | ||
customize Since: 1.1.1 | undefined | |
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:
| ||
escapeChar | " | |
Character to use as the escape character for CSV data. This will be prefixed to any data found in the fields which matches that set by the | ||
exportOptions | {} | |
Select the data to be gathered from the DataTable for export. This includes options for which columns, rows, ordering and search. Please see the | ||
extension | .csv | |
The extension to give the created file name. | ||
fieldBoundary | " | |
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 | , | |
The character(s) used to separate fields in the plain text representation of the table that is copied to the system's clipboard. | ||
filename | * | |
File name to give the created file (plus the extension defined by the | ||
footer | false | |
Indicate if the table footer should be included in the exported data or not. | ||
header | true | |
Indicate if the table header should be included in the exported data or not. | ||
newline | \n | |
The character(s) used to separate the lines of data. Please note that on Windows client's the default is | ||
text | CSV | |
The button's display text. The text can be configured using this option (see |
Examples
DataTables initialisation: Use the HTML5 CSV button:
new DataTable('#myTable', {
layout: {
topStart: {
buttons: ['csv']
}
}
});
DataTables initialisation: Use the exportOptions
to save all data, regardless of filtering:
new DataTable('#myTable', {
layout: {
topStart: {
buttons: [
{
extend: 'csv',
text: 'Copy all data',
exportOptions: {
modifier: {
search: 'none'
}
}
}
]
}
}
});