export() - Mobius1/Vanilla-DataTables GitHub Wiki
NOTE: The export() method has been deprecated and will be removed in v2.0 in favour of the Exportable extension.
type Function
Export the table data to various formats.
Usage
/**
* @param {Object} options User options
* @return {Boolean}
*/
datatable.export(options);
The options argument must be an object of which the only required property is the type property which accepts either csv, txt, json or sql as it's value. The rest are optional:
{
type: "csv" // "csv", "txt", "json" or "sql"
download: true, // trigger download of file or return the string
skipColumn: [], // array of column indexes to skip
// csv
lineDelimiter: "\n", // line delimiter for csv type
columnDelimiter: ",", // column delimiter for csv type
// sql
tableName: "myTable", // SQL table name for sql type
// json
replacer: null, // JSON.stringify's replacer parameter for json type
space: 4 // JSON.stringify's space parameter for json type
};
Examples
// Export the current page as a .csv file
dataTable.export({
type: "csv",
filename: "my-csv-file"
selection: dataTable.currentPage
});
// Export pages 1-5 as an .sql file
dataTable.export({
type: "sql",
tableName: "sql_users",
selection: [1,2,3,4,5]
});
// Export to .json file
dataTable.export({
type: "json",
});
// Export to json string, omitting the 1st, 3rd and 5th columns
var json = dataTable.export({
type: "json",
skipColumn: [0,2,4],
download: false // return formatted string instead of file
});