How to get the display datatable value in the server side script PHP during the CSV/XLS/PDF download

How to get the display datatable value in the server side script PHP during the CSV/XLS/PDF download

prashantsprashants Posts: 1Questions: 0Answers: 0
edited May 2013 in DataTables 1.9
How to get the display datatable value in the server side script PHP during the CSV/XLS/PDF download.

[code]
TableTools.DEFAULTS.aButtons = [ "csv", "xls", "pdf" ];

TableTools.BUTTONS.download = {
"sAction": "text",
"sTag": "default",
"sFieldBoundary": "",
"sFieldSeperator": "\t",
"sNewLine": "
",
"sToolTip": "",
"sButtonClass": "DTTT_button_text",
"sButtonClassHover": "DTTT_button_text_hover",
"sButtonText": "Download",
"mColumns": "all",
"bHeader": true,
"bFooter": true,
"sDiv": "",
"fnMouseover": null,
"fnMouseout": null,
"fnClick": function( nButton, oConfig ) {
var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
var iframe = document.createElement('iframe');
iframe.style.height = "0px";
iframe.style.width = "0px";
iframe.src = oConfig.sUrl+"?"+$.param(oParams);
document.body.appendChild( iframe );
},
"fnSelect": null,
"fnComplete": null,
"fnInit": null
};




var oTable = $('#example').dataTable( {
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] }
],
"aaSorting": [[0, 'desc']],
"sPaginationType": "full_numbers",

"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../<?php echo "swf"; ?>/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "download",
"sButtonText": "Download CSV",
"sUrl": "./remote.php"
}
]
},



/*"aLengthMenu": [20,50,100,200,500,1000],*/

"aLengthMenu": [[20,50,100,200,500,1000, -1], [20,50,100,200,500,1000, "All"]],
"iDisplayLength" : 20,


//column highlight
"bSortClasses": false,
"oLanguage": {
"sSearch": "Search all columns:"
},


}).columnFilter({
sPlaceHolder: "head:after",
aoColumns: [

{ type: "select" },
{ type: "select" },
{ type: "text" },
{ }
/*{ type: "select", values: [ 'Refund', 'Cancel', 'Refunded'] },*/

]
});
[/code]


remote.php (Server side file)
[code]
print_r($_REQUEST);

// parse new querystring variable "o" to represent output_mode
$output_mode = (isset($_REQUEST["o"])) ? $_REQUEST["o"] : "json";


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

echo csv_encode( $output["aaData"], $aColumns ); // see function below
} else {
// default is to output json
echo json_encode( $output );
}

/*
* csv_encode - encode data as csv, wrapping values in quotes
*/
function csv_encode($aaData, $aHeaders = NULL) {
// output headers
$output = "";
if ($aHeaders) $output .= '"' . implode('","', $aHeaders ) . '"' . "\r\n";

foreach ($aaData as $aRow) {
$output .= '"' . implode('","', $aRow) . '"' . "\r\n";
}

return $output;
}
]
}); [/code]


and why I am not able to get the value when i am set the remote.php?o=csv
This discussion has been closed.