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.
Unfortunately, activation email could not send to your email. Please try again.

Grid Not Loading DataSource on Export

Thread ID:

Created:

Updated:

Platform:

Replies:

124118 May 18,2016 06:55 AM May 26,2016 01:15 AM ASP.NET MVC 3
loading
Tags: Grid
Avi Segal
Asked On May 18, 2016 06:55 AM

I am using version 13.40.58

When exporting to Excel  using the grid, the data does not get loaded & causes an error, it excludes the datasource.


Please advise.


Thanks


Jayaprakash Kamaraj [Syncfusion]
Replied On May 19, 2016 11:29 AM

Hi Avi, 

Thanks for contacting Syncfusion support. 

Query: When exporting to Excel  using the grid, the data does not get loaded & causes an error, it excludes the datasource. 

We suspect that you have passed the grid model dataSource to server side upon exporting. In such case, we need to handle the dataSource at server side else exception will be thrown. Please refer to the below code example. 

GridFeatures.cshtml 
<script type="text/javascript"> 
   function databound(args){ 
        var grid = $('#FlatGrid').ejGrid('instance'); 
        grid.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1); // here we will splice dataSource property in ignoreOnExport method 
    } 
 
</script> 
GridController.cs 
public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            exp.Export(obj,(IEnumerable)(obj.DataSource), "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
private GridProperties ConvertGridObject(string gridProperty) 
        {.. 
 
           foreach (KeyValuePair<string, object> ds in div) 
            { 
                if (ds.Key == "dataSource") 
                { 
                    string serialize = serializer.Serialize(ds.Value); 
                    gridProp.DataSource = serializer.Deserialize<List<OrdersView>>(serialize); // here we need to deserialize tha dataSource (OrdersView as Class name) 
                } 
.. 
            return gridProp; 
        } 
    } 
} 

For your convenience we have created sample to splice the grid dataSource property on ignoreOnExport method then handle the grid model dataSource in server side. If the above is your scenario, we suggest you to deserialize the dataSource at server side as in the above code. 

If not, exception will occur when a column field is not defined in the Grid dataSource, it is obtained as null value and hence throws a null exception. Please refer to the following knowledgebase document for more information. 
 

If your scenario is different,  share the following information,                                                                           
1.       Screenshot of the stack trace of the exception obtained. 
2.       Full client and server-side code example. 
3.       Did you exporting DataTable? If, yes we have provided DataTable exporting support from v14.1.0.41 onwards. 
4.       Sample hosted link or replicate the issue in the following sample. 
 

Regards, 

Jayaprakash K. 


Avi Segal
Replied On May 25, 2016 05:06 AM

Thank you - All working

Mani Sankar Durai [Syncfusion]
Replied On May 26, 2016 01:15 AM

Hi Avi, 

Thanks for your feedback. 
 
We have happy to hear that your requirement is achieved.  
  
Regards, 
Manisankar Durai. 
                                                                                                                  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;