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

getExportModel error for Grid Excel export with column templates

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);
        }


1 Reply

VN Vignesh Natarajan Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon