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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Excel and PDF export from grid doesn't work properly with templated columns

Thread ID:

Created:

Updated:

Platform:

Replies:

141312 Dec 5,2018 03:23 PM UTC Dec 19,2018 11:01 AM UTC ASP.NET MVC - EJ 2 7
loading
Tags: Grid
Tomislav Tustonic
Asked On December 5, 2018 03:23 PM UTC

Hello

It seems that the export to Excel or Pdf from the grid doesn't work when there's a templated column.
For example, I have a viewmodel object Address

    public class Address
    {
        public string City { get; set; }
        public string Street { get; set; }
    }

and the grid column defined like this:

   col.Field("Address").Template("${Address.City}, ${Address.Street}").Add();

It is displayed fine in the grid, but when I try to export to Excel it doesn't work at all, and export to Pdf shows [object Object] in the Address field:

Sample controller and views are attached

Attachment: Test_9c2e9851.zip

Venkatesh Ayothi Raman [Syncfusion]
Replied On December 6, 2018 01:00 PM UTC

Hi Tomislav, 
Thanks for using Syncfusion products. 
Currently Essential JS 2 Grid don’t have support for template exporting and we have already logged this “Provide support for template exporting” as feature request list. This implementation will be included in any of upcoming release.  

Regards,
Venkatesh Ayothiraman. 


Tomislav Tustonic
Replied On December 6, 2018 01:21 PM UTC

Hello
This is bad.
When do you expect this feature released?

Tom

Mohammed Farook J [Syncfusion]
Replied On December 10, 2018 11:55 AM UTC

 
Hi Tomislav, 
 
We have already considered “Provide support for template exporting” as a feature list. This feature list is like the below requirements. 
 
  • Need to provide excel support for hyperlink template column.
  • If you render component as column template , than it display element html string .
For example: 
If you render button as a column template, then it display like a html element string. That is “<button id=’button’>Click Button</button>”. 
 
If these requirement lists are different from your requirement , then please provide details about your column template. 
 
Regards, 
J Mohammed Farook 


Tomislav Tustonic
Replied On December 10, 2018 12:02 PM UTC

Hello

My requirement is like the one in my first post, for example the Address object, with template "${Address.City}, ${Address.Street}" it should render City, Street both in Excel column and in Pdf. I don't need hyperlinks and buttons in the exported data.

Thanks, Tom


Venkatesh Ayothi Raman [Syncfusion]
Replied On December 11, 2018 11:46 AM UTC

  
Hi Tomislav, 
 
Thanks for the update. 
 
As we said before, we have already logged this “Provide support for template exporting” as feature request list. This implementation will be included in any of upcoming release. Until use the following workaround for your requirement. Here, we have achieved your requirement by using ExcelQueryCellInfo and PdfQueryCellInfo events of the grid. Please find the below code example and sample for your reference. 
 
[code example] 
@{ 
    ViewBag.Title = "Grid Sample"; 
} 
 
<div> 
   @Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).AllowPdfExport().PdfQueryCellInfo("PdfQueryCellInfo"). 
ExcelQueryCellInfo("ExcelQueryCellInfo").AllowExcelExport().ToolbarClick("toolbarClick").Columns(col => 
{ 
    ... 
   col.HeaderText("TemplateColumn").Width("150").Template("#template").Add(); 
 
}).AllowPaging().PageSettings(page => page.PageSize(8)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true) 
.Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "ExcelExport", "PdfExport" }).Render() 
 
</div> 
 
<script id="template" type="text/template"> 
    <div> 
        ${ShipCountry}, ${ShipCity} 
    </div> 
</script> 
 
<script> 
    function toolbarClick(args) { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
        if (args.item.id === 'Grid_excelexport') { 
            gridObj.excelExport(); 
        } else if (args.item.id === 'Grid_pdfexport') { 
            gridObj.pdfExport(); 
        } 
    } 
 
    function ExcelQueryCellInfo(args) { 
        if (args.value.length === 0) { 
            args.value = args.data.ShipCountry + ", " + args.data.ShipCity; 
        } 
    } 
 
    function PdfQueryCellInfo(args) { 
        if (args.value.length === 0) { 
            args.value = args.data.ShipCountry + ", " + args.data.ShipCity; 
        } 
    } 
</script> 
 
Please find the sample in below link. 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Venkatesh Ayothiraman.

Tomislav Tustonic
Replied On December 18, 2018 02:07 PM UTC

Thanks

Will the templates like the one I described work in the future releases, or it will always be necessary to fix output using JavaScript like in your reply?

Tom

Mohammed Farook J [Syncfusion]
Replied On December 19, 2018 11:01 AM UTC

Hi Tom, 
 
After provided support for “template exporting” , you didn’t include any additional codes for exporting template column When you render the column template from Grid field value only,  otherwise if you have render any custom elements in  your column template we must be used ExcelQueryCellInfo /PdfQueryCellInfo  event for exporting template column. 
 
Regards, 
J Mohammed Farook 


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

;