Jump to content

Edit History

ps8modules

ps8modules

Why do you think that if you give a piece of code without specifying that we will give you a quality solution?
Is it the configuration of the module or is it the controller of the module or the class of the module?
How is CSV generated, as plain text or fputcsv ?
Should the CSV be available from a URL, or just generate and download the file?
Is it used in the JavaScript module?
This is only some of the information that is needed.

 

in module:

$csv = $this->getCSVData(); /* generated CSV as text with separator */
$def = array('csvData' => $csv, 'csvName' => 'my-csv-file.csv');
Media::addJsDef($def);

in javascript:

$(document).ready(function(){
  	$( "#my-button-download-generated-csv" ).click(function(e) {
      	downloadCSVFileGenerated(csvData, csvName);
    });
});

function downloadCSVFileGenerated(csvData, csvName){
    let a = document.createElement('a');
    a.setAttribute('style', 'display:none;');
    document.body.appendChild(a);
    let blob = new Blob([csvData], { type: 'text/csv' });
    let url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = csvName;
    a.click();    
}

 

ps8modules

ps8modules

Why do you think that if you give a piece of code without specifying that we will give you a quality solution?
Is it the configuration of the module or is it the controller of the module or the class of the module?
How is CSV generated, as plain text or fputcsv ?
Should the CSV be available from a URL, or just generate and download the file?
Is it used in the JavaScript module?
This is only some of the information that is needed.

×
×
  • Create New...