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.
Syncfusion Feedback

Export to PDF, XLS and Word with OData Datasource

Thread ID:

Created:

Updated:

Platform:

Replies:

120040 Aug 26,2015 05:00 AM UTC Aug 31,2015 07:27 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Jim Woods
Asked On August 26, 2015 05:00 AM UTC

How do you properly export your grid if you are using OData as the datasource?

I have seen plenty of examples that use the WebApi Controller with a Northwind dataContext (MS Sample db).  
For example: http://mvc.syncfusion.com/demos/web/grid/exportinggrid.

However, my data source is embedded in the grid and is a rest service (see below).  How should this be called appropriately?  

@(Html.EJ().Grid<object>("Grid")
     .AllowPaging()
        .AllowSorting()
            .Datasource(d => d.URL("https://MyOdataQuery")
                .CrossDomain(true))
            
                .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
                    {
                        items.AddTool(ToolBarItems.ExcelExport);
                        items.AddTool(ToolBarItems.WordExport);
                        items.AddTool(ToolBarItems.PdfExport);
                    }))
                        .Mappers(map => map.ExportToExcelAction("ExcelAction")
                .ExportToPdfAction("PdfAction").ExportToWordAction("WordAction")
              )
               
        .Columns(col =>
            {
                col.Field("ApplicationID").HeaderText("Application ID").TextAlign(TextAlign.Right).Add();
                col.Field("Visits").HeaderText("Visits").TextAlign(TextAlign.Right).Add();

            })
        
         .ClientSideEvents(eve => { eve.Load("load"); })
         .AllowFiltering()
)

Balaji Marimuthu [Syncfusion]
Replied On August 27, 2015 01:32 PM UTC

Hi Jim,

We have analyzed your code.

Are you using the WebApiController wih Odata to the rest service or are you using OdataController only?

If you are using OdataController only, then could you please share with us the following:

1.       Share us the version of Odata details. Are you using the Odatav4.
2.       A sample if you can create and send one will be really helpful for us to locate the cause of the issue



If you are using the WebAPI controller, then please refer to the below document for helpful information:
http://helpjs.syncfusion.com/js/grid/exporting


Regards,
Balaji Marimuthu


Jim Woods
Replied On August 28, 2015 03:37 AM UTC

I am using Odata 4.  

The call goes to a separate api.  It is not a part of the solution I am working on, rather it is a separate project/solution.  

With that in mind, are you suggesting that the export requires its own separate rest call within that api?  If so, does this mean the api requires the syncFusion dlls as well?



Balaji Marimuthu [Syncfusion]
Replied On August 31, 2015 07:27 AM UTC

Hi Jim,


We have prepared an Exporting sample in OdataV4. Please refer to the sample and code example as below,

Sample: Exporting-Odata4

@(Html.EJ().Grid<object>("Editing")

          .Datasource(ds => { ds.URL("/odata/Orders").Adaptor(AdaptorType.ODataV4Adaptor); })

        

          .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>

                     {

                         items.AddTool(ToolBarItems.ExcelExport);

                         items.AddTool(ToolBarItems.WordExport);

                         items.AddTool(ToolBarItems.PdfExport);

                     }))

             .Mappers(map => map.ExportToExcelAction("/odata/Orders/ExcelExport")

               .ExportToPdfAction("/odata/Orders/PdfExport").ExportToWordAction("/odata/Orders/WordExport"))

        .AllowPaging()

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width(50).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").Width(50).Add();

            col.Field("ShipCity").HeaderText("ShipCity").Width(50).Add();


        })

)


Also, Map the route in WebApiConfig to perform the Export Action as follows,

config.Routes.MapHttpRoute(

                name: "DefaultApi",

                routeTemplate: "odata/{controller}/{action}/{id}", //if you are using odata controller

                defaults: new { id = RouteParameter.Optional }

            );


// if you are using WebApi controller


config.Routes.MapHttpRoute(

                name: "DefaultActionApi",

                routeTemplate: "api/{controller}/{action}/{id}",

                defaults: new { id = RouteParameter.Optional }

            );


Query: #1 the call goes to a separate api.  It is not a part of the solution I am working on, rather it is a separate project/solution. With that in mind, are you suggesting that the export requires its own separate rest call within that api?  


Exporting doesn’t require own separate rest call within that API. You can use it as a separate project/solution and map the Exporting Action to Grid by using Mappers.


Please refer to the following code example,


@(Html.EJ().Grid<object>("Editing")

         

             . . .


             .Mappers(map => map.ExportToExcelAction("/odata/Orders/ExcelExport")

               .ExportToPdfAction("/odata/Orders/PdfExport").ExportToWordAction("/odata/Orders/WordExport"))

        )


Query: #2 if so, does this mean the api requires the syncFusion dlls as well? 


Yes, the Syncfusion dll’s are required to perform the Exporting Operation. Please refer to the Syncfusion dll in your Exporting project/solution.


Please refer to the dependencies for Exporting from the following link:

http://helpjs.syncfusion.com/js/dependencies


Please get back to us if you need any further assistance.

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.

Warning Icon 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.Close Icon

;