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

Error in Ej.export.dll when calling from grid

Hi,

I have grid with custom columns that are populated on demand.


<div id="gridPanelDetailsMaintenance" class="row">
            @(Html.EJ().Grid<DocTracerPortal.Models.Visual.VisualGridDocument>("GridDocumentMaintenance")
                 .Datasource((IEnumerable<DocTracerPortal.Models.Visual.VisualGridDocument>)ViewBag.documentVisualResultsSource)
                 .AllowSorting()
                 .IsResponsive(true)
                 .AllowSelection(true)
                 .AllowResizeToFit(true)
                 .ShowColumnChooser()
                 .AllowGrouping()
                 .SelectionType(SelectionType.Multiple)
                 .SelectionSettings(select => { select.SelectionMode(mode => { mode.AddMode(SelectionMode.Row); }); })
                 .ContextMenuSettings(contextMenu =>
                 {
                     contextMenu.EnableContextMenu().DisableDefaultItems(true)
                         .CustomContextMenuItems(new List<Syncfusion.JavaScript.Models.CustomContexMenuItems>() {
                                                                                    new  Syncfusion.JavaScript.Models.CustomContexMenuItems() { Id = "1", Text = "Edit properties (all) <img src='/Images/grid_DocumentDetails/options/edit.png' style='width:20px;height:20px' />" } ,
                                                                                    new  Syncfusion.JavaScript.Models.CustomContexMenuItems() { Id = "2", Text = "Server Storage View <img src='/Images/grid_DocumentDetails/options/Dashboard.png' style='width:20px;height:20px' />" } ,
                                                                                    //new  Syncfusion.JavaScript.Models.CustomContexMenuItems() { Id = "3", Text = "Show Versions of This Document only <img src='/Images/grid_DocumentDetails/options/find-16x16.png' style='width:20px;height:20px' />" } ,//Not for MVP
                                                                                    new  Syncfusion.JavaScript.Models.CustomContexMenuItems() { Id = "4", Text = "Assign Group Security <img src='/Images/grid_DocumentDetails/options/securityAssignment_16px.png' style='width:20px;height:20px' />" } ,
                                                                                     }); // CustomContext menu items

                 })
                 .ClientSideEvents(eve =>
                 {
                     eve.ContextClick("contextClickMaintenance").ContextOpen("contextOpenMaintenance").RecordClick("rowSelectMaintenance");
                     eve.ActionComplete("actionComplete").RecordDoubleClick("rdoubleClickMaintenance");
                     eve.ActionComplete("completeMaintenance");
                 })
                 .EditSettings(edit =>
                 {
                     edit.AllowDeleting().AllowEditing().EditMode(EditMode.DialogTemplate).TitleColumn("Name").DialogEditorTemplateID("#templateMaintenance");
                 })
                 .ToolbarSettings(toolbar =>
                 {
                     toolbar.ShowToolbar().ToolbarItems(items =>
                     {
                         items.AddTool(ToolBarItems.Edit);
                         items.AddTool(ToolBarItems.Delete);
                         items.AddTool(ToolBarItems.Update);
                         items.AddTool(ToolBarItems.Cancel);
                         items.AddTool(ToolBarItems.PrintGrid);
                         items.AddTool(ToolBarItems.ExcelExport);
                         items.AddTool(ToolBarItems.WordExport);
                         items.AddTool(ToolBarItems.PdfExport);
                     });
                 })
                 .Mappers(map => map.ExportToExcelAction("/Default/ExportToExcel").ExportToPdfAction("/Default/ExportToPdf").ExportToWordAction("/Default/ExportToWord"))
                 .AllowResizing(true)
                 //.AllowPaging()
                 .AllowFiltering()
                 //.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
                 .FilterSettings(filter => { filter.FilterType(FilterType.Menu); })
                 //.FilterSettings(d => d.FilterType(FilterType.FilterBar))
                 .Columns(col =>
                 {
                     col.Field(p => p.Id).HeaderText("Document Id").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Visible(false).Add();
                     col.HeaderText("In/Out").Template("#ColumnStatus").TextAlign(TextAlign.Center).Add();
                     col.HeaderText("Options").Template("#ColumnOption").TextAlign(TextAlign.Left).Add();
                     col.HeaderText("Ver").Template("#ColumnVersionsMaintenance").TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.DocumentNumber).Tooltip("#colTip").HeaderText("Document #").TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.Name).HeaderText("File Name").Tooltip("#colTip").AllowEditing(false).TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.DocumentTitle).HeaderText("Document Title").Tooltip("#colTip").TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.PageSizeId).HeaderText("PageSize ID").EditType(EditingType.Dropdown).TextAlign(TextAlign.Right).Visible(false).Width(75).Add();
                     col.Field(p => p.PageSize).Tooltip("#colTip").HeaderText("Page Size").TextAlign(TextAlign.Left).EditType(EditingType.Dropdown).Add();
                     col.Field(p => p.DocumentRevisionNumber).Tooltip("#colTip").HeaderText("Revision #").TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.TransmittalNumber).Tooltip("#colTip").HeaderText("Transmittal Number").TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.OriginalSizeMB).Tooltip("#colTip").HeaderText("Size").AllowEditing(false).TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.DateUploaded).Tooltip("#colTip").HeaderText("Date Created").AllowEditing(false).TextAlign(TextAlign.Left).Format("{0:MM/dd/yyyy hh:mm:ss}").Add();
                     col.Field(p => p.DateReceivedString).Tooltip("#colTip").HeaderText("Date Received").AllowEditing(false).TextAlign(TextAlign.Left).Format("{0:MM/dd/yyyy hh:mm:ss}").Add();
                     col.Field(p => p.UploadedBy).HeaderText("Uploaded By").TextAlign(TextAlign.Left).AllowEditing(false).Add();
                     col.Field(p => p.Tags).Tooltip("#colTip").HeaderText("Tags").TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.Comments).Tooltip("#colTip").HeaderText("Comments").TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.AreaId).HeaderText("Area ID").EditType(EditingType.Dropdown).TextAlign(TextAlign.Right).Visible(false).Width(75).Add();
                     col.Field(p => p.AreaName).Tooltip("#colTip").HeaderText("Area").TextAlign(TextAlign.Left).EditType(EditingType.Dropdown).Add();
                     col.Field(p => p.DocumentCategoryId).HeaderText("Document Category ID").EditType(EditingType.Dropdown).Visible(false).TextAlign(TextAlign.Right).Width(75).Add();
                     col.Field(p => p.DocumentCategoryName).Tooltip("#colTip").HeaderText("Category").TextAlign(TextAlign.Left).EditType(EditingType.Dropdown).Add();
                     col.Field(p => p.DocumentStatusId).HeaderText("Document Status ID").EditType(EditingType.Dropdown).Visible(false).TextAlign(TextAlign.Right).Width(75).Add();
                     col.Field(p => p.DocumentStatusName).Tooltip("#colTip").HeaderText("Document Status").TextAlign(TextAlign.Left).EditType(EditingType.Dropdown).Add();
                     col.Field(p => p.Extension).Tooltip("#colTip").HeaderText("Ext").AllowEditing(false).TextAlign(TextAlign.Left).Add();
                     col.Field(p => p.NumberOfPages).Tooltip("#colTip").HeaderText("Pages").EditType(EditingType.Numeric).TextAlign(TextAlign.Right).Add();
                     //col.Field(p => p.ForceCheckIn).HeaderText("Force check in").TextAlign(TextAlign.Left).Add();
                     //col.Field(p => p.ReadOnly).HeaderText("Read Only").TextAlign(TextAlign.Left).Add();
                 })
            )
        </div>

The grid works fine. However, I have issues with the export methods. I'm getting this error in the call



The stack trace of the error is

   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 Syncfusion.EJ.Export.ExcelExport.Export(GridProperties gridmaodel, IEnumerable datasource, String excelname, ExcelVersion excelversion, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme)
   at DocTracerPortal.Controllers.Maintenance.DefaultController.ExportToExcel(String GridModel) in D:\CodeBitbucket\doctracerportal\DocTracerPortal\Controllers\Maintenance\DefaultController.cs:line 627

I checked the objects that are passed to the Export method and they are populated.

Model

"{\"allowPaging\":false,\"showColumnChooser\":true,\"gridLines\":\"both\",\"allowSorting\":true,\"showStackedHeader\":false,\"selectedRecords\":[],\"stackedHeaderRows\":[],\"allowFiltering\":true,\"allowMultipleExporting\":false,\"allowSelection\":true,\"allowGrouping\":true,\"showSummary\":false,\"allowResizing\":true,\"allowResizeToFit\":true,\"allowTextWrap\":false,\"allowCellMerging\":false,\"enablePersistence\":false,\"enableFocusout\":false,\"selectedRowIndex\":-1,\"allowSearching\":false,\"enableToolbarItems\":false,\"allowReordering\":false,\"allowRowDragAndDrop\":false,\"enableTouch\":true,\"columnLayout\":\"auto\",\"locale\":\"en-US{\\\"EmptyRecord\\\":\\\"No records to display\\\",\\\"GroupCaptionFormat\\\":\\\"{{:headerText}}: {{:key}} - {{:count}} \\\",\\\"GroupText\\\":\\\" item\\\",\\\"True\\\":\\\"true\\\",\\\"False\\\":\\\"false\\\"}\",\"allowMultiSorting\":false,\"exportToExcelAction\":\"/Default/ExportToExcel\",\"exportToWordAction\":\"/Default/ExportToWord\",\"exportToPdfAction\":\"/Default/ExportToPdf\",\"_groupingCollapsed\":[],\"selectionSettings\":{\"selectionMode\":[\"row\"],\"enableToggle\":false,\"cellSelectionMode\":\"flow\"},\"resizeSettings\":{\"resizeMode\":\"nextcolumn\"},\"groupSettings\":{\"showDropArea\":true,\"showToggleButton\":false,\"showGroupedColumn\":true,\"showUngroupButton\":true,\"enableDropAreaAutoSizing\":true,\"captionFormat\":null,\"groupedColumns\":[]},\"contextMenuSettings\":{\"enableContextMenu\":true,\"contextMenuItems\":[\"Add Record\",\"Edit Record\",\"Delete Record\",\"Sort In Ascending Order\",\"Sort In Descending Order\",\"Next Page\",\"Last Page\",\"Previous Page\",\"First Page\",\"Save\",\"Cancel\",\"Grouping\",\"Ungrouping\"],\"customContextMenuItems\":[{\"id\":\"1\",\"text\":\"Edit properties (all) <img src='/Images/grid_DocumentDetails/options/edit.png' style='width:20px;height:20px' />\"},{\"id\":\"2\",\"text\":\"Server Storage View <img src='/Images/grid_DocumentDetails/options/Dashboard.png' style='width:20px;height:20px' />\"},{\"id\":\"4\",\"text\":\"Assign Group Security <img src='/Images/grid_DocumentDetails/options/securityAssignment_16px.png' style='width:20px;height:20px' />\"}],\"subContextMenu\":[],\"disableDefaultItems\":true},\"filterSettings\":{\"filterType\":\"menu\",\"filterBarMode\":\"immediate\",\"showFilterBarStatus\":true,\"statusBarWidth\":450,\"showPredicate\":false,\"filteredColumns\":[],\"enableInterDeterminateState\":true,\"maxFilterChoices\":1000,\"enableCaseSensitivity\":false,\"immediateModeDelay\":1500,\"enableComplexBlankFilter\":true,\"blankValue\":\"\"},\"searchSettings\":{\"fields\":[],\"key\":\"\",\"operator\":\"contains\",\"ignoreCase\":true},\"sortSettings\":{\"sortedColumns\":[]},\"toolbarSettings\":{\"showToolbar\":true,\"toolbarItems\":[\"edit\",\"delete\",\"update\",\"cancel\",\"printGrid\",\"excelExport\",\"wordExport\",\"pdfExport\"],\"customToolbarItems\":[]},\"minWidth\":0,\"currentIndex\":0,\"rowDropSettings\":{\"dropMapper\":null,\"dragMapper\":null,\"dropTargetID\":null},\"scrollSettings\":{\"width\":1560,\"height\":0,\"enableTouchScroll\":true,\"allowVirtualScrolling\":false,\"virtualScrollMode\":\"normal\",\"frozenRows\":0,\"frozenColumns\":0,\"buttonSize\":18,\"autoHide\":false,\"scrollerSize\":18,\"scrollOneStepBy\":57,\"enableVirtualization\":false},\"textWrapSettings\":{\"wrapMode\":\"both\"},\"summaryRows\":[],\"enableRTL\":false,\"enableAltRow\":true,\"childGrid\":null,\"keySettings\":null,\"mergeCellInfo\":null,\"create\":null,\"actionBegin\":null,\"actionComplete\":\"completeMaintenance\",\"actionFailure\":null,\"beginEdit\":null,\"endEdit\":null,\"endAdd\":null,\"endDelete\":null,\"beforeBatchAdd\":null,\"beforeBatchSave\":null,\"beforeBatchDelete\":null,\"batchAdd\":null,\"batchDelete\":null,\"cellSave\":null,\"cellEdit\":null,\"resizeStart\":null,\"resizeEnd\":null,\"resized\":null,\"load\":null,\"destroy\":null,\"rowSelecting\":null,\"rowSelected\":null,\"cellSelecting\":null,\"cellSelected\":null,\"columnSelecting\":null,\"columnSelected\":null,\"columnDragStart\":null,\"columnDrag\":null,\"columnDrop\":null,\"dataBound\":null,\"recordClick\":\"rowSelectMaintenance\",\"recordDoubleClick\":\"rdoubleClickMaintenance\",\"templateRefresh\":null,\"rightClick\":null,\"detailsCollapse\":null,\"detailsExpand\":null,\"contextOpen\":\"contextOpenMaintenance\",\"contextClick\":\"contextClickMaintenance\",\"columns\":[{\"field\":\"Id\",\"headerText\":\"Document Id\",\"textAlign\":\"right\",\"isPrimaryKey\":true,\"visible\":false,\"width\":75,\"showInColumnChooser\":true,\"allowResizing\":true,\"type\":\"string\"},{\"field\":\"\",\"headerText\":\"In/Out\",\"template\":\"#ColumnStatus\",\"textAlign\":\"center\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"allowSorting\":false,\"allowFiltering\":false,\"allowGrouping\":false,\"type\":null},{\"field\":\"\",\"headerText\":\"Options\",\"template\":\"#ColumnOption\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"allowSorting\":false,\"allowFiltering\":false,\"allowGrouping\":false,\"textAlign\":\"left\",\"type\":null},{\"field\":\"\",\"headerText\":\"Ver\",\"template\":\"#ColumnVersionsMaintenance\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"allowSorting\":false,\"allowFiltering\":false,\"allowGrouping\":false,\"textAlign\":\"left\",\"type\":null},{\"field\":\"DocumentNumber\",\"headerText\":\"Document #\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"Name\",\"headerText\":\"File Name\",\"allowEditing\":false,\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"DocumentTitle\",\"headerText\":\"Document Title\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"PageSizeId\",\"headerText\":\"PageSize ID\",\"editType\":\"dropdown\",\"textAlign\":\"right\",\"visible\":false,\"width\":75,\"showInColumnChooser\":true,\"allowResizing\":true,\"type\":\"number\"},{\"field\":\"PageSize\",\"headerText\":\"Page Size\",\"editType\":\"dropdown\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"DocumentRevisionNumber\",\"headerText\":\"Revision #\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"TransmittalNumber\",\"headerText\":\"Transmittal Number\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"OriginalSizeMB\",\"headerText\":\"Size\",\"allowEditing\":false,\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"DateUploaded\",\"headerText\":\"Date Created\",\"allowEditing\":false,\"format\":\"{0:MM/dd/yyyy hh:mm:ss}\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"DateReceivedString\",\"headerText\":\"Date Received\",\"allowEditing\":false,\"format\":\"{0:MM/dd/yyyy hh:mm:ss}\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"UploadedBy\",\"headerText\":\"Uploaded By\",\"allowEditing\":false,\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"Tags\",\"headerText\":\"Tags\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"Comments\",\"headerText\":\"Comments\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"AreaId\",\"headerText\":\"Area ID\",\"editType\":\"dropdown\",\"textAlign\":\"right\",\"visible\":false,\"width\":75,\"showInColumnChooser\":true,\"allowResizing\":true,\"type\":\"number\"},{\"field\":\"AreaName\",\"headerText\":\"Area\",\"editType\":\"dropdown\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"DocumentCategoryId\",\"headerText\":\"Document Category ID\",\"editType\":\"dropdown\",\"textAlign\":\"right\",\"visible\":false,\"width\":75,\"showInColumnChooser\":true,\"allowResizing\":true,\"type\":\"number\"},{\"field\":\"DocumentCategoryName\",\"headerText\":\"Category\",\"editType\":\"dropdown\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"DocumentStatusId\",\"headerText\":\"Document Status ID\",\"editType\":\"dropdown\",\"textAlign\":\"right\",\"visible\":false,\"width\":75,\"showInColumnChooser\":true,\"allowResizing\":true,\"type\":\"number\"},{\"field\":\"DocumentStatusName\",\"headerText\":\"Document Status\",\"editType\":\"dropdown\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"Extension\",\"headerText\":\"Ext\",\"allowEditing\":false,\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"textAlign\":\"left\",\"type\":\"string\"},{\"field\":\"NumberOfPages\",\"headerText\":\"Pages\",\"editType\":\"numeric\",\"textAlign\":\"right\",\"tooltip\":\"#colTip\",\"visible\":true,\"showInColumnChooser\":true,\"allowResizing\":true,\"type\":\"number\"}],\"isResponsive\":true,\"enableResponsiveRow\":false,\"virtualLoading\":null,\"keyConfigs\":{\"focus\":\"e\",\"insertRecord\":\"45\",\"deleteRecord\":\"46\",\"editRecord\":\"113\",\"saveRequest\":\"13\",\"cancelRequest\":\"27\",\"nextPage\":\"34\",\"previousPage\":\"33\",\"lastPage\":\"ctrl+alt+34\",\"firstPage\":\"ctrl+alt+33\",\"nextPager\":\"alt+34\",\"previousPager\":\"alt+33\",\"firstCellSelection\":\"36\",\"lastCellSelection\":\"35\",\"firstRowSelection\":\"ctrl+36\",\"lastRowSelection\":\"ctrl+35\",\"upArrow\":\"38\",\"downArrow\":\"40\",\"rightArrow\":\"39\",\"leftArrow\":\"37\",\"moveCellRight\":\"9\",\"moveCellLeft\":\"shift+9\",\"selectedGroupExpand\":\"alt+40\",\"totalGroupExpand\":\"ctrl+40\",\"selectedGroupCollapse\":\"alt+38\",\"totalGroupCollapse\":\"ctrl+38\",\"multiSelectionByUpArrow\":\"shift+38\",\"multiSelectionByDownArrow\":\"shift+40\"}}"

Object



searchResults



I think it could be a problem because of the custom columns. But, I'm not sure how can I debug this further or test my theory.

Could you give some help of what could be happening?

Kind regards,

Juan Acosta

 

16 Replies

JK Jayaprakash Kamaraj Syncfusion Team December 8, 2016 12:55 PM UTC

Hi Juan,  
 
Thanks for contacting Syncfusion support.  
 
We have created a sample and checked the issue by using the provided code snippets, but we were unable to reproduce the reported issue. Refer to the sample in following link.  
 
 
Please share the following information to find the cause of the issue. 
 
1.     Scenario to reproduce the issue.  
2.     Essential studio and browser version details.  
3.     Code example for loadDetailsGridFromCache(). 
3.     Share sample if possible or modify the attached sample as issue reproducible.  
  
Regards,  
 
Jayaprakash K. 



JA Juan Acosta December 9, 2016 07:42 AM UTC

Hi Jayaprakash,

1.     Scenario to reproduce the issue. 

* Load the screen with the current grid.
      * Then select a dropdownlist that will generate the event and call the controller.
      * The controller will return the new results list (storing the results list in cache).
      * the results list will repopulate the grid again.
      * the user will call the export buttons on click in the desired toolbar icon.

2.     Essential studio and browser version details. 

       Version=14.2450.0.26
       Browser
                Google Chrome Version 54.0.2840.99 m (64-bit)
                      FF 50.0.2

3.     Code example for loadDetailsGridFromCache().

        private void loadDetailGridFromCache()
        {
            if (HttpRuntime.Cache.Get("DocumentDetailsSearchFor" + ClaimsPrincipal.Current.FindFirst("dt_userid").Value) != null)
                this.searchDocumentsResults = (List<VDocumentShort>)HttpRuntime.Cache.Get("DocumentDetailsSearchFor" + ClaimsPrincipal.Current.FindFirst("dt_userid").Value);
        }


        The code simply recovered the results from cache to avoid another call to the backend.

4.     Share sample if possible or modify the attached sample as issue reproducible. 

         I will need to do something similar. I cannot pass the original code for the complexity of the backend calls required.

There is any way to activate more levels of debugging with the Syncfusion controls?

Kind regards,

Juan


JK Jayaprakash Kamaraj Syncfusion Team December 14, 2016 01:23 PM UTC

Hi Juan, 
 
The mentioned issue is occurred, due to when the columns bound to the Grid are not defined in the Grid dataSource. We have already discussed the same issue in following knowledge base document.  
 
 
For example if the column field name “Employee1” is not defined in Grid dataSource, the null exception will be thrown while exporting the Grid dataSource. So, please ensure the columns bound to the Grid are defined in the Grid dataSource before exporting the Grid 
 
Regards, 
 
Jayaprakash K. 



JA Juan Acosta December 14, 2016 11:12 PM UTC

Hi Jayaprakash,

I understand now the issue.  However, there is any way that I modified the model to avoid using the custom column IN/OUT and Options. Becuase, those columns are loaded dynamically from information received and are never bind directly to the gridDataSource. I need those columns for showing some specified values to the user. Generally speaking, it does not make sense to export them to any other format.

Could you help me to achieve that.

Kind regards,

Juan


JK Jayaprakash Kamaraj Syncfusion Team December 15, 2016 01:37 PM UTC

Hi Juan, 
 
To overcome this problem we suggest you to splice the grid dataSource property on ignoreOnExport method then handle the grid model dataSource in server side with Type Builder. Please refer to the below code example. 

@(Html.EJ().Grid<object>("FlatGrid") 
        .. 
 
       }).ClientSideEvents(eve=>eve.DataBound("databound"))) 
<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 ActionResult GridFeatures() 
        { 
            var DataSource = new NorthwindDataContext().OrdersViews.Take(50).ToList(); 
            ViewBag.datasource = DataSource; 
            return View(); 
        } 
        public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            JavaScriptSerializer serializer = new JavaScriptSerializer(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            Type tableType = GetTableType(obj); 
 
            // Create instance of Array to the dynamic table type 
            var inst = Array.CreateInstance(tableType, 1); 
      
 
            string griddata = serializer.Serialize(obj.DataSource); 
 
 
            // serialize the export data as object array 
 
            obj.DataSource = serializer.Deserialize(griddata, inst.GetType()) as object[]; 
 
 
            exp.Export(obj, (IEnumerable)(obj.DataSource), "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
        public static Type GetTableType(GridProperties gridProperty) 
        { 
            // Create needed TypeBuilder helpers 
            AppDomain myDomain = Thread.GetDomain(); 
            AssemblyName myAsmName = new AssemblyName("Anonymous"); 
            AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run); 
 
            ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule(myAsmName.Name); 
            TypeBuilder myTypeBuilder = myModBuilder.DefineType("TestClass", TypeAttributes.Public); 
 
            foreach (var col in gridProperty.Columns) 
            { 
                Type PropertyType; 
                var PropertyName = col.Field; 
 
                if (col.CustomAttributes.Count > 0) 
                { 
                    var colTypeAct = col.CustomAttributes["type"]; 
                    if (colTypeAct.Equals("duration")) 
                    { 
                        col.Type = "string"; 
                    } 
 
                } 
                if (col.HeaderText.Contains("<BR>")) 
                { 
                    col.HeaderText = col.HeaderText.Replace("<BR>", ""); 
 
                } 
                switch (col.Type) 
                { 
                    case "number": PropertyType = Type.GetType("System.Decimal"); 
                        break; 
 
                    case "string": PropertyType = Type.GetType("System.String"); 
                        break; 
                    case "boolean": PropertyType = Type.GetType("System.Boolean"); 
                        break; 
                    case "date": PropertyType = Type.GetType("System.DateTime"); 
                        break; 
                    default: PropertyType = Type.GetType("System.String"); 
                        break; 
                } 
 
                FieldBuilder PropertyFieldBuilder = myTypeBuilder.DefineField(PropertyName.ToLower(), PropertyType, FieldAttributes.Private); 
 
                PropertyBuilder PBuilder = myTypeBuilder.DefineProperty(PropertyName, System.Reflection.PropertyAttributes.HasDefault, PropertyType, null); 
 
                MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; 
 
                MethodBuilder getPropertyBuilder = myTypeBuilder.DefineMethod("get" + PropertyName, getSetAttr, PropertyType, Type.EmptyTypes); 
 
                // Constructing IL Code for get and set Methods. 
                ILGenerator GetPropGenerator = getPropertyBuilder.GetILGenerator(); 
 
                GetPropGenerator.Emit(OpCodes.Ldarg_0); 
                GetPropGenerator.Emit(OpCodes.Ldfld, PropertyFieldBuilder); 
                GetPropGenerator.Emit(OpCodes.Ret); 
 
                MethodBuilder setPropertyBuulder = myTypeBuilder.DefineMethod("set_" + PropertyName, getSetAttr, null, new Type[] { PropertyType }); 
 
                ILGenerator SetPropGenerator = setPropertyBuulder.GetILGenerator(); 
 
                SetPropGenerator.Emit(OpCodes.Ldarg_0); 
                SetPropGenerator.Emit(OpCodes.Ldarg_1); 
                SetPropGenerator.Emit(OpCodes.Stfld, PropertyFieldBuilder); 
                SetPropGenerator.Emit(OpCodes.Ret); 
 
                PBuilder.SetGetMethod(getPropertyBuilder); 
 
                PBuilder.SetSetMethod(setPropertyBuulder); 
            } 
 
            ConstructorInfo objCtor = typeof(object).GetConstructor(new Type[-1 + 1]); 
            ConstructorBuilder pointCtor = myTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes); 
 
            ILGenerator ctorIL = pointCtor.GetILGenerator(); 
 
            // Constructing IL Code for the Type Constructor. 
            ctorIL.Emit(OpCodes.Ldarg_0); 
            ctorIL.Emit(OpCodes.Call, objCtor); 
            ctorIL.Emit(OpCodes.Ret); 
 
            return myTypeBuilder.CreateType(); 
        } 
        private static PropertyInfo[] GetProperties(object obj) 
        { 
            return obj.GetType().GetProperties(); 
        } 
 
        private GridProperties ConvertGridObject(string gridProperty) 
        { 
            JavaScriptSerializer serializer = new JavaScriptSerializer(); 
            IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable)); 
            GridProperties gridProp = new GridProperties(); 
            foreach (KeyValuePair<string, object> ds in div) 
            { 
      
                    var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); 
                    if (property != null) 
                    { 
                        Type type = property.PropertyType; 
                        string serialize = serializer.Serialize(ds.Value); 
                        object value = serializer.Deserialize(serialize, type); 
                        property.SetValue(gridProp, value, null); 
                    } 
               
            } 
            return gridProp; 
        } 
 
Attached GridController.cs file. Please refer to the below link. 
 
  
Regards, 
 
Jayaprakash K. 
 



JA Juan Acosta December 19, 2016 03:36 AM UTC

Hi Jayaprakash,

Thank you so much for your help, I added the method and review the fields that give problems as null.



One last question, How can I remove the first two columns from the result?

Kind regards,

Juan


JK Jayaprakash Kamaraj Syncfusion Team December 20, 2016 01:12 PM UTC

Hi Juan, 
 
We suggest you to remove the first two columns in Grid model before exporting and then export the Grid with updated Grid model using export method. Please refer to the below code example. 

        public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            JavaScriptSerializer serializer = new JavaScriptSerializer(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            Type tableType = GetTableType(obj); 
 
            // Create instance of Array to the dynamic table type 
            var inst = Array.CreateInstance(tableType, 1); 
      
 
            string griddata = serializer.Serialize(obj.DataSource); 
 
 
            // serialize the export data as object array 
 
            obj.DataSource = serializer.Deserialize(griddata, inst.GetType()) as object[]; 
            for (int i = 0; i < 2; i++) 
            { 
                obj.Columns.RemoveAt(i); 
            } 
            exp.Export(obj, (IEnumerable)(obj.DataSource), "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 

Regards, 
 
Jayaprakash K. 



JA Juan Acosta December 20, 2016 11:52 PM UTC

Hi Jayaprakash,

Thanks for your reply. That works perfectly. I have a question for you.

I also print the grid.

I found that I need to modify the printing options.