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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

getExportModel error for Grid Excel export with column templates

Thread ID:

Created:

Updated:

Platform:

Replies:

141205 Nov 29,2018 03:01 PM UTC Nov 30,2018 07:13 AM UTC ASP.NET MVC 1
loading
Tags: Grid
Megan Moore
Asked On November 29, 2018 03:01 PM UTC

I am receiving the following error when attempting to export my grid to Excel.  Can you help me figure out what I'm missing?

ej.web.all.min.js:10 Uncaught TypeError: i.columns[r].template.indexOf is not a function
    at Object._getExportModel (ej.web.all.min.js:10)

Cshtml:
            $("#dashboard").ejGrid({
                allowReordering: true,
                allowMultiSorting: true,
                allowPaging: true,
                allowSorting: true,
                allowFiltering: true,
                allowTextWrap: true,
                allowResizing: true,
                allowHiding: true,
                cellSelecting: "dbCellSelect",
                selectionSettings: { allowSelection: true, selectionType: "single", cellSelecting: "dbCellSelect", selectionMode: [ej.Grid.SelectionMode.Cell] },
                unHideColsOnDblClick: true,
                ExportToExcelAction: "@Url.HttpRouteUrl("Default", new { controller = "Dashboard", action = "ColumnTemplateExportToExcel" })",
                toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Search, ej.Grid.ToolBarItems.ExcelExport] },
                mappers: { ExportToExcelAction: "@Url.HttpRouteUrl("Default", new { controller = "Dashboard", action = "ColumnTemplateExportToExcel" })" },
                pageSettings: { pageSize: 5, pageSizeList: [5, 25, 50] },
                filterSettings: { filterType: "Menu" },
                columns: [
                    { field: "Column1", headerText: "Column1", textAlign: ej.TextAlign.Left, visible: false },
                    { field: "Column2", headerText: "Column2", textAlign: ej.TextAlign.Left, visible: !columnsHidden.includes('@HideColumn2') },
                    { field: "Column3", headerText: "Column3", textAlign: ej.TextAlign.Left, visible: !columnsHidden.includes('@HideColumn3') },
                    { field: "Column4", headerText: "Column4", textAlign: ej.TextAlign.Center, template: true, templateID: "#Column4Template", visible: !columnsHidden.includes('@HideColumn4') },
                    { field: "Column5", headerText: "Column5", textAlign: ej.TextAlign.Left, visible: !columnsHidden.includes('@HideColumn5') },
                    { field: "Column6", headerText: "Column6", textAlign: ej.TextAlign.Left, template: true, templateID: "#Column6Template", visible: false },
                    { field: "Column7", headerText: "Column7", textAlign: ej.TextAlign.Left, visible: !columnsHidden.includes('@HideColumn7') },
                    { field: "Column8", headerText: "Column8", textAlign: ej.TextAlign.Center, template: true, templateID: "#Column8Template", visible: !columnsHidden.includes('@HideColumn8') },
                    { field: "Column9", headerText: "Column9", textAlign: ej.TextAlign.Center, template: true, templateID: "#Column9Template", visible: !columnsHidden.includes('@HideColumn9') },
                    { field: "Column10", headerText: "Column10", textAlign: ej.TextAlign.Left, visible: !columnsHidden.includes('@HideColumn10') },
                    { field: "Column11", headerText: "Column11", textAlign: ej.TextAlign.Left, visible: !columnsHidden.includes('@HideColumn11') },
                    { field: "Column12", headerText: "Column12", textAlign: ej.TextAlign.Center, template: true, templateID: "#Column12Template", visible: !columnsHidden.includes('@HideColumn12') },
                    { field: "Column13", headerText: "Column13", textAlign: ej.TextAlign.Left, visible: false },
                    { field: "Column14", headerText: "Column14", textAlign: ej.TextAlign.Left, visible: false },
                    { field: "Column15", headerText: "Column15", textAlign: ej.TextAlign.Left, visible: false },
                    { field: "Column15", headerText: "Column15", textAlign: ej.TextAlign.Left, visible: false }
                ],
                sortSettings: { sortedColumns: [{ field: "Column3", direction: "descending" }, { field: "Column4", direction: "ascending" }] }
                });

            $.ajax({
                type: "GET",
                url: "@Url.HttpRouteUrl("DefaultApi", new { controller = "DashboardsApi", action = "GetDashboards" })",
                datatype: "json",
                success: function (response) {
                    var dashboardGridObj = $("#dashboard").ejGrid("instance");
                    dashboardGridObj.ignoreOnExport.splice(dashboardGridObj.ignoreOnExport.indexOf('pageSettings'), 1);
                    dashboardGridObj.dataSource(response);
            })

Controller:
        public void ColumnTemplateExportToExcel(string GridModel)
        {
            ExcelExport exp = new ExcelExport();
            GridExcelExport GridExp = new GridExcelExport
            {
                //GridExp.QueryCustomSummaryInfo = SummaryCellInfo;
                Theme = "flat-saffron",
                FileName = "DashboardExport.xlsx",
                IsTemplateColumnIncluded = true
            };
            DashboardsApiController rdbController = new DashboardsApiController();
            var dashboards = rdbController.GetDashboards();
            GridProperties obj = ConvertGridObject(GridModel);
            obj.ExcelColumnTemplateInfo = TemplateInfo;
            exp.Export(obj, dashboards, GridExp);
        }


Vignesh Natarajan [Syncfusion]
Replied On November 30, 2018 07:13 AM UTC

Hi Megan, 
 
Thanks for using Syncfusion products. 
 
From your query, we understand you are facing issue while exporting the Grid with template. We have prepared a sample and we are able to reproduce the reported issue while using your code example. We have deprecated the property called the templateID. Instead you can use template property of ejGrid to define the id of script tag.  
 
Refer the below code example 
 
$("#Grid").ejGrid({ 
                // the datasource "window.employeeView" is referred from jsondata.min.js 
                dataSource: ej.DataManager(window.employeeView).executeLocal(ej.Query().take(8)), 
                allowPaging: true, 
                pageSettings: { pageSize: 4 }, 
                columns: [ 
                                               { headerText: "Employee Image", template: "#columnTemplate", textAlign: "center", width: 110 }, 
                                               { field: "EmployeeID", headerText: "Employee ID", isPrimarykey: true, editType: ej.Grid.EditingType.NumericEdit, textAlign: ej.TextAlign.Right, width: 90 }, 
                                               { field: "FirstName", headerText: "First Name", width: 90 }, 
                                               { field: "LastName", headerText: "Last Name", width: 90 }, 
                                               { field: "BirthDate", headerText: "Birth Date", width: 90, format: "{0:MM/dd/yyyy}", textAlign: ej.TextAlign.Right }, 
                                               { field: "Country", headerText: "Country", width: 80 } 
 
                ] 
            }); 
 
Refer the below link for the release notes regarding the deprecated properties 
 
 
Please get back to us if you have any queries. 
 
Regards, 
Vignesh Natarajan 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon