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

Export Failing

Hello, I'm attempting to export to pdf from javascript and get the following error from the api. Does anyone know what this error means and if there's anything I can do to get it working?

<Error><Message>An error has occurred.</Message><ExceptionMessage>Object reference not set to an instance of an object.</ExceptionMessage><ExceptionType>System.NullReferenceException</ExceptionType><StackTrace>   at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordCell(Object row, Column column)
   at Syncfusion.EJ.Export.GridExcelExport.<>c__DisplayClasse.<ProcessRecordRow>b__d(Column column)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordRow(Object row)
   at Syncfusion.EJ.Export.GridExcelExport.RenderRecord()
   at Syncfusion.EJ.Export.GridExcelExport.ProcessGridContents()
   at Syncfusion.EJ.Export.GridExcelExport.IterateElements()
   at Syncfusion.EJ.Export.GridExcelExport.ExportHandler()
   at Syncfusion.EJ.Export.GridExcelExport.ExecuteResult(GridProperties GridModel, Object dataSource)
   at Syncfusion.EJ.Export.GridExcelExport.ExportHelper(GridProperties gridModel, Object dataSource)
   at Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, Object dataSource, Boolean multipleExport)
   at Syncfusion.EJ.Export.ExcelExport.Export(GridProperties gridmaodel, Object datasource, String excelname, ExcelVersion excelversion, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme)
   at Northwind.JSGridExportController.ExcelExport() in c:\Users\karthigeyan.krishnam\Desktop\ExportingServices\ExportingServices\Northwind\JSGridExportController.cs:line 33
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClassf.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
   at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)</StackTrace></Error>


My grid code follows:

                    $('#Grid').ejGrid({
                        dataSource: reportDetails,
                        enableRowHover: true,
                        allowTextWrap: false,
                        allowPaging: true,
                        allowSorting: true,                   
                        allowFiltering: true,
                        allowResizing: false,
                        allowResizeToFit: false,
                        allowKeyboardNavigation: true,
                        allowSearching: true,
                        allowMultipleExporting:true,
                        enablePersistance:true,
                        pageSettings: { pageSize: 25 },
                        filterSettings: { filterType: "excel" },
                        toolbarSettings: { showToolbar: true, toolbarItems: ["search", ej.Grid.ToolBarItems.ExcelExport] },
                        exportToExcelAction: 'http://js.syncfusion.com/ExportingServices/api/JSGridExport/ExcelExport',
                        columns: [
                                    { field: "Date", width: 115 },
                                    { field: "Name", width: 120 },
                                    { field: "Product" },
                                    { field: "Variation", width: 120},
                                    { field: "Buy", width: 90},
                                    { field: "Order Status", width: 90 },
                                    { field: "Payment Status", width: 90 },
                                    { field: "Shipping Status", width: 100 }
                                ]
                    });

Thanks

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team June 21, 2016 08:58 AM UTC

Hi Chris, 

We are able to reproduce the problem with the given code example. ejGrid exports the Grid based on the model values given in the plugin. If the columns present in the Grid is different or not available in the datasource bound to the export method, it will not export the Grid and throws an error. The following Exporting Service link is prepared based on the columns present in the demo showcased next link and it is exclusively only for our JS sample browser sample. 



ejGrid’s Exporting action needs server-side operation and so you have to maintain the exporting action at server-side and export the columns and dataSource bound to the Grid. In the following example, we have C# has the backend for handling the exporting action. Refer to the following code example.  

<div id="Grid"></div> 
<script type="text/javascript"> 
    $(function () { 
        var json = @Html.Raw(Json.Encode(ViewBag.dataSource)); 
        $("#Grid").ejGrid({ 
            dataSource: json, 
            allowPaging: true, 
            exportToExcelAction:'/Home/ExportToExcel', 
            toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.ExcelExport] }, 
            . . . . . 
              . . . . 
        }); 
    }); 
</script> 
 
        public void ExportToExcel(string GridModel) //Server-side 
        { 
            ExcelExport exp = new ExcelExport(); 
            var DataSource = OrderRepository.GetAllRecords().Take(50).ToList(); 
            DataOperations operation = new DataOperations(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 

You have to refer the following assemblies in your project to export to excel.  

Syncfusion.EJ 
Syncfusion.EJ.Export 
Syncfusion.Xlsio.Base  

Refer to the following Help Document for the server-side configuration of exporting Grid. 


We have prepared a sample that can be downloaded from the following location. 


Regards, 
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon