Export to CSV/PDF without Tabletools
Export to CSV/PDF without Tabletools
So currently, Tabletools is a great plugin for Export to CSV/PDF etc. I understand flash is used in order to locally save the exported data. Now that we are moving to a Flash-free future, has someone worked on implementing the same using Javascript (Not sure though if it is even possible with the latest JS features).
Also, is there a plugin that anyone may have written to implement it from server-side, which may not use flash?
Also, is there a plugin that anyone may have written to implement it from server-side, which may not use flash?
This discussion has been closed.
Replies
You might add a new flag to the server_processing.php file that indicates output_mode
[code]
// parse new querystring variable "o" to represent output_mode
$output_mode = (isset($_REQUEST["o"])) ? $_REQUEST["o"] : "json";
[/code]
and check the $output_mode flag before outputting at the end of the script.
[code]
if ($output_mode == "csv") {
header("Content-type: text/csv");
header("Cache-Control: no-store, no-cache");
header('Content-Disposition: attachment; filename="filename.csv"'); // you can change the default file name here
// send the aaData and aColumns headers
echo csv_encode( $output["aaData"], $aColumns ); // EDIT: this was originally listed as $output->aaData which doesn't work on $output. it's an associative array, not "object"
}
else {
// default is to output json
echo json_encode( $output );
}
[/code]
and write a csv encoding routine
[code]
function csv_encode($aaData, $aHeaders = NULL) {
// output headers
if ($aHeaders) echo implode(',', $aHeaders ) . "\r\n";
foreach ($aaData as $aRow) {
echo implode(',', $aRow) . "\r\n";
}
}[/code]
You could add slightly more robust code to wrap data with double quotes, or escape various characters