How can I download CSV file on click of DownloadCSV button

Hello!
I want to download the CSV file of displayed product data on the click of the DownloadCSV button. The CSV file name should be "product.csv". So, please provide me the best solution for it.

1 Reply

AD Arunkumar Devendiran Syncfusion Team May 12, 2020 09:00 AM UTC

Hi Ishan Shah 
 
Thank you for contacting Syncfusion support. 
 
We have checked your reported requirement and we would inform you that we have created the sample for your scenario. In that, we have saved the Csv file with a specified file name while clicking the Downloadcsv button. Please refer the below code snippet and sample link. 
 
Index.cshtml 
@Html.EJS().Spreadsheet("spreadsheet").OpenUrl("Open").SaveUrl("Save").Sheets(sheet => 
  { 
      sheet.Name("Product").Ranges(ranges => 
      { 
          ranges.DataSource((IEnumerable<object>)ViewBag.DefaultData).Add(); 
      }).Add(); 
  }).Render() 
<button class="e-btn" id="saveButton">DownloadCSV</button> 
 
<script> 
    document.getElementById('saveButton').addEventListener('click', function () { 
        var ssObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet'); 
        ssObj.save({ saveType: "Csv", fileName:"product" }); 
    }); 
 
</script> 
 
 
Sample link: 
 
Could you please check the above sample and let us know whether this is fulfilling your requirement or get back to us if you need further assistance. 
 
Regards, 
Aunkumar D 


Loader.
Up arrow icon