CSV download on custom button click

Hi,
I need help to export/download CSV in my custom button outside of the grid
In the toolbar click working fine but do not need this.
1. I want to click the download button then the CSV file started to download

code and seaport are attached.

Thank you





Attachment: code_b0a67e2a.zip

3 Replies 1 reply marked as answer

VS Vignesh Sivagnanam Syncfusion Team February 24, 2021 10:26 AM UTC

Hi Rizwan 

Greetings from Syncfusion support 

Based on your query, we found that you want to perform CSV exporting in the grid using the external button. To achieve your requirement we need to call the csvExport method in the button click function. Please refer the below Code Example for your reference, 

Code Example : 
@using Syncfusion.EJ2.Grids 

@{ 
    ViewBag.Title = "Grid Adaptor"; 
<button onclick="export()">Export</button> 
    @(        @Html.EJS().Grid<gridmvclocalization.Controllers.OrdersDetails>("Grid").DataSource((IEnumerable<object> 
            )ViewBag.dataSource).AllowExcelExport().Columns(col =>{ 
        …………………………………………….. 
      }).AllowPaging()}).Render() 
    ) 
<script> 
  function export(e) { 
    var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];   //Grid Instance 
    grid.csvExport();                                                                                                            //Grid Exporting 
  } 
</script> 

Regards 
Vignesh Sivagnanam 



RI Rizwan February 25, 2021 02:37 PM UTC

Thank you its works

Marked as answer

VS Vignesh Sivagnanam Syncfusion Team February 26, 2021 10:49 AM UTC

Hi Rizwan 

We are happy to hear that the provided solution works fine at your end. 

Please get back to us if you need any further assistance. 

Regards, 
Vignesh Sivagnanam 


Loader.
Up arrow icon