2

I'm trying to export my DHTMLX Grid to a CSV file. I have the framework for it set up, but am running in an issue where if I try to export more than ~25 rows, it fails. No error message or anything. Below is my code:

Javascript

myGrid.csvParser = myGrid.csvExtParser;
myGrid.setCSVDelimiter('|');
myGrid.csv.row = "endOfRow";

var gridCsvData = myGrid.serializeToCSV();

$.post("data/export.php?csvdata="+gridCsvData);

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: text/csv");
header("Content-Disposition: attachment; filename=grid.csv");
header("Pragma: no-cache");
header("Expires: 0");

readfile('grid.csv');

Any help is appreciated. I assume it's some kind of size limit problem on the POST and I've tried modifying the limit to 20MB in the .htaccess file. As I said, this works perfectly with only a few rows (<25), but once I try to export any more than that it never generates the .csv file.

1 Answer 1

2

I guess that $.post (from jQuery right?) doesn't handle such a huge url. You should add a parameter that can be handle as parameter of the HTTP POST query:

$.post(
  "data/export.php", 
  { 
    csvdata: gridCsvData
  }
);
Sign up to request clarification or add additional context in comments.

4 Comments

Works great thanks man..still having trouble getting it to prompt the user to save the file. Any idea on why that wouldn't be popping up? It is saving on the server just not prompting.
Have you tried with application/csv instead of text/csv in the Content-type ?
Yeah, I've gone back and forth between those two. No difference that I could see
It might depend on the browser too. You might have a look at these questions/answers: stackoverflow.com/search?q=%5Bphp%5D+force+download

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.