- Home
- Forum
- ASP.NET MVC
- Grid ForeignKey export problem
Grid ForeignKey export problem
Hello
I have a problem
when I try to do an Excell export from a Grid with ForeignKey
I have done
my grid, like example from the version 12.4.0.30 (Grid\Foreign Key Column).
@(Html.EJ().Grid<OrdersView>("ForeignKey")
.Datasource((IEnumerable<object>)ViewBag.dataSource1)
.
.
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
.
items.AddTool(ToolBarItems.ExcelExport);
.
});
})
.Columns(col =>
{
.
col.Field("EmployeeID").HeaderText("Employee
Name").ForeignKeyField("EmployeeID").ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2).TextAlign(TextAlign.Left).Width(90).Add();
.
})
)
I have done my
controller export like the example (Grid\Exporting Grid)
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, ViewBag.dataSource1, "Export.xlsx",
ExcelVersion.Excel2010, false, false, "flat-saffron");
}
… but when I
run the Export I have an error.
How I can do
the Excell export from de Grid\Foreign Key Column example?
Thanks
Thanks for using Syncfusion Products.
We have analyzed your provided code snippet and we would like to let you know that if we are using foreign key column in Grid, we need to specify the dataSource to the foreign key column of GridProperties in the export method. Please find the following code snippet:
[View] @(Html.EJ().Grid<ForeignkeyExport.OrdersView>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.dataSource1) .AllowPaging() .ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.ExcelExport); items.AddTool(ToolBarItems.WordExport); items.AddTool(ToolBarItems.PdfExport); }); }) .Columns(col => { col.Field("EmployeeID").HeaderText("Employee Name").ForeignKeyField("EmployeeID") .ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2) .TextAlign(TextAlign.Left).Width(90).Add(); . . . . . ) [Controller] public void ExportToExcel(string GridModel) { ExcelExport exp = new ExcelExport(); var DataSource = new NorthwindDataContext().OrdersViews.ToList(); GridProperties obj = ConvertGridObject(GridModel); obj.Columns[2].DataSource = new NorthwindDataContext().EmployeeViews.ToList(); exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); } public void ExportToWord(string GridModel) { WordExport exp = new WordExport(); var DataSource = new NorthwindDataContext().OrdersViews.ToList(); GridProperties obj = ConvertGridObject(GridModel); obj.Columns[2].DataSource = new NorthwindDataContext().EmployeeViews.ToList(); exp.Export(obj, DataSource, "Export.docx", false, false, "flat-saffron"); } public void ExportToPdf(string GridModel) { PdfExport exp = new PdfExport(); var DataSource = new NorthwindDataContext().OrdersViews.ToList(); GridProperties obj = ConvertGridObject(GridModel); obj.Columns[2].DataSource = new NorthwindDataContext().EmployeeViews.ToList(); exp.Export(obj, DataSource, "Export.pdf", false, false, "flat-saffron"); } |
For your convenience we have attached a sample in the sample in following link: ForeignkeyExport.zip
If above solution doesn’t meet your requirement, kindly share us your exporting error screen shot that will be helpful to provide better solution.
Please let us know if you have any queries.
Regards,
Balaji Mairmuthu
Hi Balaji.
Thanks for
your help. Your solution was perfect.
Thanks for the update.
Please get back to us if youhave any concerns.
Regards,
Balaji Marimuthu
- 3 Replies
- 2 Participants
-
JP Juan Peiró Llobet
- May 5, 2015 08:26 AM UTC
- May 7, 2015 12:06 PM UTC