- Home
- Forum
- ASP.NET MVC
- Grid Not Loading DataSource on Export
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
SIGN IN To post a reply.
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.
Sample: http://www.syncfusion.com/downloads/support/forum/124118/ze/SyncfusionMvcApplication82-1516137963
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.
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
AS Avi Segal
- May 18, 2016 10:55 AM UTC
- May 26, 2016 05:15 AM UTC