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

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

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

7 Replies

VA Venkatesh Ayothi Raman Syncfusion Team 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. 



TT Tomislav Tustonic December 6, 2018 01:21 PM UTC

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

Tom


MF Mohammed Farook J Syncfusion Team 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 



TT Tomislav Tustonic 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



VA Venkatesh Ayothi Raman Syncfusion Team 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.


TT Tomislav Tustonic 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


MF Mohammed Farook J Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon