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
close icon

Grid Not Loading DataSource on Export

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


3 Replies

JK Jayaprakash Kamaraj Syncfusion Team May 19, 2016 03:29 PM UTC

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. 



AS Avi Segal May 25, 2016 09:06 AM UTC

Thank you - All working


MS Mani Sankar Durai Syncfusion Team May 26, 2016 05:15 AM UTC

Hi Avi, 

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


Loader.
Live Chat Icon For mobile
Up arrow icon