Hi Antonio,
Thanks for contacting Syncfusion support.
Based on your update you have mentioned that you have a Grid with detailTemplate. In the detailTemplate you have used TreeGrid and you need to export to excel or PDF with the TreeGrid.
By default in grid if we have used HTML elements in template, then while exporting we can export only the HTML elements as a string. So, while using detailTemplate, the elements which has been rendered within the template is exported as a string. So, it is not feasible to export treegrid with the detailsTemplate.If you want to export only the HTML elements that you have used in detailTemplate, then you need to set IncludeDetailRow as true in the parameter of the export method. You can handle template elements using server side event while exporting grid to various files such as Excel, PDF and Word.For more information refer the below help document.
Regards,Prasanna Kumar N.S.V
@(Html.EJ().Grid<EmployeeView>("DetailTemplate")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.ClientSideEvents(eve => eve.DetailsDataBound("databound"))
.ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.ExcelExport);
items.AddTool(ToolBarItems.WordExport);
items.AddTool(ToolBarItems.PdfExport);
}))
.Columns(col =>
{
-------------------------
})
.DetailsTemplate("#tabGridContents")
)
<script id="tabGridContents" type="text/x-jsrender">
<div id="treegrid"></div>
</script>
[controller.cs]
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
var DataSource = new NorthwindDataContext().EmployeeViews.ToList();
GridProperties obj = ConvertGridObject(GridModel);
GridExcelExport exp2 = new GridExcelExport() { IncludeDetailRow = true, Theme = "flat-saffron", FileName = "Export.xlsx" };
obj.ExcelDetailTemplateInfo = templateInfo;
exp.Export(obj, DataSource, exp2);
}
public void templateInfo(object currentCell, object row)
{
IRange range = (IRange)currentCell;
object templates;
foreach (var data in row.GetType().GetProperties())
{
if (range.Value.Contains(data.Name))
{
templates = row.GetType().GetProperty(data.Name).GetValue(row, null);
range.Value = range.Value.Replace(data.Name, templates.ToString());
var charsToRemove = new string[] { "{", "}", "<b>", ":", "</b>", "<br />", "style", "=", "class", "</div>", "<p>", "</p>", "detail", "<b", ">", };
foreach (var c in charsToRemove)
{
range.Value = range.Value.ToString().Replace(c, string.Empty);
}
range.HorizontalAlignment = ExcelHAlign.HAlignCenter;
}
}
}
|