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 ForeignKey export problem

Thread ID:

Created:

Updated:

Platform:

Replies:

119012 May 5,2015 04:26 AM May 7,2015 08:06 AM ASP.NET MVC 3
loading
Tags: Grid
Juan Peiró Llobet
Asked On May 5, 2015 04:26 AM

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


Balaji Marimuthu [Syncfusion]
Replied On May 6, 2015 09:33 AM

Hi Juan,

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

Juan Peiró Llobet
Replied On May 6, 2015 10:34 AM

 

Hi Balaji.

Thanks for your help. Your solution was perfect.


Balaji Marimuthu [Syncfusion]
Replied On May 7, 2015 08:06 AM

Hi Juan,
Thanks for the update.
Please get back to us if youhave any concerns.
Regards,
Balaji Marimuthu

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.

;