I'm exporting my DHTMLX grid to csv and have successfully been able to create the .CSV file. The problem I'm having is that it isn't prompting the user to save/open the file. I'm using a $.post call from javascript to send the CSV string to PHP, then writing that string to csv. For some reason it isn't creating a prompt for the user, but it is successfully writing the file and saving on the server. Below is the relevant code:
JS:
myGrid.csvParser = myGrid.csvExtParser;
myGrid.setCSVDelimiter('|');
myGrid.csv.row = "endOfRow";
var gridCsvData = myGrid.serializeToCSV();
$.post(
"data/export.php",
{
csvdata: gridCsvData
}
);
PHP (export.php):
$csvData = $_REQUEST['csvdata'];
$csv = explode('endOfRow',$csvData);
$myfile = "grid.csv";
$fh = fopen($myfile, 'w') or die("can't open file");
foreach($csv as $line) {
fputcsv($fh, explode('|',$line),',','"');
}
fclose($fh);
//Redirect output to a client's web browser (csv)
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=grid.csv");
header("Pragma: no-cache");
header("Expires: 0");
This code works perfectly in the sense that it exports the Grid exactly how I want it and saves it to 'grid.csv'. The problem is that it isn't prompting the user to save the file. Is this a problem with my PHP headers or do I need to put something in the $.post to prompt on success? Thanks for any help!