Export ot xls

I have successfully implemented a toolbar network to export filtered data to xls. I would like to export all network data with an external button, but I have no success because I always get only filtered data. I appreciate any help.
Thanks in advance

5 Replies 1 reply marked as answer

MS Manivel Sellamuthu Syncfusion Team January 8, 2021 05:40 PM UTC

Hi Enisa, 

Greetings from Syncfusion support. 

You can export all the Grid data by applying a new query in the  grid data module. Please refer the below code example and sample for more information. 

<div class="control-section"> 
    <button id="store" class="e-btn e-primary" onclick="exportAllData()">Export All Data</button> 
 
    @Html.EJS().Grid("Grid").AllowExcelExport().DataSource(ds => ds.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor")).ToolbarClick("toolbarClick").Columns(col => 
{ 
 . . . 
}).Height("400").AllowPaging().Toolbar(new List<string> 
        () { "ExcelExport" }).AllowFiltering().FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).Render() 
</div> 
 
<script> 
    function toolbarClick(args) { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
        if (args.item.text === 'Excel Export') { 
            gridObj.excelExport(); 
        } 
    } 
 
    function exportAllData() { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
        gridObj.getDataModule().executeQuery(new ej.data.Query()).then(e => { 
            gridObj.excelExport({ dataSource: e.result }); 
        }) 
 
    } 
</script> 


Please let us know, if you need further assistance. 

Regards, 
Manivel 



EM Enisa Manjo January 11, 2021 08:29 AM UTC

Dear Manivel,

thanks fro your help, but we are using E1 grid, and your solution do not fit me :(
Here is my grid. I would like to use external controller for the both purposes.
 Thanks in advance

@(Html.EJ().Grid<LogViewModel>("GridLog")
     ...
                    .ToolbarSettings(tool => tool.ShowToolbar().ToolbarItems(item =>
                    {
                        item.AddTool(ToolBarItems.ExcelExport);
                    }))
                .ClientSideEvents(s =>
                {
                    s.ActionBegin("onGridLogActionBegin");
                    s.ActionComplete("onGridLogActionComplete");
  
                })
                 .Mappers(map => map.ExportToExcelAction("Log/GridSelectedLogExcelExport"))
...
    .Columns(columns =>
    {
       ...
    })
    .Datasource(ds =>
    {
        ds.URL(@Url.Action("Read_Log", "Log"));
        ds.Adaptor(AdaptorType.UrlAdaptor);

    })


PK Padmavathy Kamalanathan Syncfusion Team January 12, 2021 12:29 PM UTC

Hi Enisa, 
 
Thanks for contacting Syncfusion Forums. 
 
Query: I would like to export all network data with an external button, but I have no success because I always get only filtered data 
 
From your query we suspect that you need to export complete Grid data even when you have applied filtering for the Grid. We have achieved your requirement by adding the “filterSettings” property to ignoreOnExport (IgnoreOnExport holds the list  of properties to be ignored while performing exporting). Calling “addIgnoreOnExport” by passing “filterSettings” as parameter will ignore filterSettings on export and thus complete Grid data will be exported. 
 
Please check the below help documentation, 
 
Also please check the below code snippet, 
 
@(Html.EJ().Button("Excel").Text("Excel").ClientSideEvents(evt => evt.Click("exportGrid"))) 
 
@(Html.EJ().Grid<object>("Grid") 
                                .Datasource(datasource => datasource.URL(@Url.Action("DataSource")) 
                                .Adaptor(AdaptorType.UrlAdaptor)) 
                                .AllowPaging().AllowFiltering() 
                                .Columns(col => 
                                { 
                                    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add(); 
                                    col.Field("CustomerID").HeaderText("Customer ID").Add(); 
                                    col.Field("EmployeeID").Add(); 
                                    col.Field("Freight").Add(); 
                                }) 
) 
<script> 
 
    function exportGrid(args) { 
        var gridObj = $("#Grid").ejGrid("instance"); //grid instance. here "Grid" is grid's ID 
        gridObj.addIgnoreOnExport("filterSettings");  
        // adding filterSettings to ignoreOnExport so that complete grid data will be exported instead of filtered data 
        var action = args.model.text + "Export"; 
        gridObj.export("/Grid/ExportToExcel/" + action); 
 
    } 
</script> 

 
 
We have created sample for your reference. You can download the same from the below link, 
 
If above solution does not meet your requirement, share us the below details, 
  1. Please explain in detail about the issue you are facing/requirement with exact scenario and video demo
  2. Screenshot of error with complete stack trace (if any)
  3. Share us your complete Grid rendering code (both client and server end)
  4. Please confirm us whether you are applying initial filtering and also let us know how you bind data to Grid
  5. If possible, share us issue reproducible sample(with issue replication steps) or reproduce the issue in the sample shared above
 
Regards, 
Padmavathy Kamalanathan 


Marked as answer

EM Enisa Manjo January 12, 2021 01:15 PM UTC

Dear Padmavathy,

Thanks for your help. Everything works fine :)

Regards,
Enisa


PK Padmavathy Kamalanathan Syncfusion Team January 13, 2021 09:46 AM UTC

Hi Enisa, 
 
We are glad to hear that you have achieved your requirement. 
 
Kindly get back to us for further assistance. 
 
Regards, 
Padmavathy Kamalanathan 


Loader.
Up arrow icon