We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Export to Excel from Grid with sorting

Hi ,

I am doing export to Excel from Grid. I have a dataset that populate the grid. If I do export to Excel then it exports the whole dataset. My question is

if in the grid I did sorting/ filtering, and then try to export its not reflected in the exporting. It does the initial whole export. is there a way I can achieve this?
To capture whats in the grid? The grid results may change due to sorting/filtering.

3 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team March 30, 2017 07:00 AM UTC

Hi Guha, 

Thanks for contacting Syncfusion support. 

We checked in our sample and when we export after we perform sorting or filtering operation, the filtered data or sorted data has been exported instead of exporting the whole data set. So, we unable to reproduce the mentioned issue at our end.  

To find out the root cause, we need the following details.  

1. Have you used IEnumerable data or Datatable in your sample?  

2. Code example of a Grid view page and server-side.  

3. Essential Studio Version details. 

4. If possible, replicate the issue in the attached sample.  

Note: In above sample we used DataTable in Grid.  


Regards, 
Prasanna Kumar N.S.V 



MG MUNMUN GUHA March 30, 2017 02:04 PM UTC

Hi,

First of all the sample is in VS2015 ASP MVC where as when I opened the incident I stated that itis VS2010 ASP.NET. I am unable to open what you have, Please send a sample that is VS2010 AND ASP.NET 4.

The support is really slow when I need the solution asap. It will be helpful you provide a direct number.
To speed it up I am sending a snippet of my code  and please advice

 protected void Page_Load(object sender, EventArgs e)
        {
            //BindDataSource();
            int recCount;
            DataSet oDS = DataAccessMain.GetStandardReportsExcel(5, "B");
            recCount = oDS.Tables[0].Rows.Count;
            if (recCount > 0)
            { 
               
                Grid1.DataSource = oDS.Tables[0];------->  that's where the grid is getting data 
                Grid1.DataBind();
            }
        }

 protected void Grid1_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
//export to excel. By doing this it is always exporting all data . not wht's in the grid that time. please update the code as necessary or send a sample that i can open,
            GridExcelExport exp1 = new GridExcelExport();
            ExcelExport exp = new ExcelExport();
            DataSet oDS = DataAccessMain.GetStandardReportsExcel(5, "B");
            var DataSource = oDS.Tables[0];
   
            exp.Export(Grid1.Model, Grid1.DataSource, "BuildingReport.xlsx", ExcelVersion.Excel2010, true, true, "default-theme");
            
          
        }


PK Prasanna Kumar Viswanathan Syncfusion Team March 31, 2017 09:28 AM UTC

Hi Guha, 

According to your request,  we attached the sample in VS2010 with ASP.NET 4 and please download the sample from the following link 


In your code example we found that you have used dataTable in your application. We checked in our sample and when we export after we perform sorting or filtering operation, the filtered data or sorted data has been exported.  
 
Find the code example :  
 

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
    <ej:Grid ID="Grid" runat="server" AllowSorting="True" AllowGrouping="true" AllowResizing="true" AllowPaging="True" AllowFiltering="True" OnServerExcelExporting="Grid_ServerExcelExporting">        
        <FilterSettings FilterType="Excel" /> 
        <ToolbarSettings ShowToolbar="True" ToolbarItems="excelExport" /> 
        ----------------- 
     </ej:Grid> 
</asp:Content> 

-------------------------------------------------------------------- 

private DataTable GetDataTale() 
        { 
 
            DataTable dt = new DataTable("Table"); 
            dt.Columns.AddRange(new DataColumn[3] { 
                            new DataColumn("Id", typeof(int)), 
                            new DataColumn("Name", typeof(string)), 
                            new DataColumn("Qty",typeof(string)) }); 
            DataRow dr = null; 
 
            for (int i = 0; i <= 100; i++) 
            { 
                dr = dt.NewRow(); 
                dr[0] = i; 
                dr[1] = "Product Name " + i.ToString(); 
                dr[2] = "Qty" + i.ToString(); 
                dt.Rows.Add(dr); 
            } 
            return dt; 
 
        } 
        protected void Grid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) 
        { 
            ExcelExport exp = new ExcelExport(); 
            DataTable dt = GetDataTale(); 
            exp.Export(Grid.Model, dt, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime"); 
        } 


To find out the root cause, we need some clarifications. 

1. Ensure that you have the get filteredColumns or sortedColumns in Grid.Model in Exporting method. 

 

2. Essential Studio Version details. 

3. If possible, replicate the issue in the attached sample.  

Please provide us the above details so that we could provide you the solution as early as possible. 

Query : “The support is really slow when I need the solution asap. It will be helpful you provide a direct number.” 

Our Support system is designed to provide a response to each customer by maintaining strict standard of quality.  With the depth of support, we provide with custom samples, live remote debugging through web meetings, as well as our commitment to provide on demand patches for each customer from our world-wide customer base and different time zones, it is logistically difficult for us to commit to a support response at a timeline that is less than 24hours.We use Citrix GoTo meeting App for meetings with customer only in case if we are unable to reproduce the issue after getting all the prerequisites. 

Regards, 
Prasanna Kumar N.S.V 
 


Loader.
Live Chat Icon For mobile
Up arrow icon