Export to Excel of both Parent/Child grid's data

2 posts, 0 answers
  1. Rizwan
    Rizwan avatar
    12 posts
    Member since:
    Sep 2015

    Posted 17 Jan 2017 Link to this post

    I have a scenario in which I have a grid which has a child grid in it which shows up when user clicks on one column of it. Following is my code

    Parent Grid has ".ClientDetailTemplateId("template")" which refers to script id "template" which has definition of the child grid.
    How I can export data of both grids together when one clicks on EXPORT TO EXCEL button?
    Right now it only exports PARENT grid's data..no child grid's data is being exported.

    Parent Grid:
    .Columns(columns =>
        columns.Bound(c => c.FacilityName).Title("Facility Name").HeaderHtmlAttributes(new {style = "white-space: normal;font-weight:bold"}).MinScreenWidth   (100).HtmlAttributes(new {style = "color:blue;font-weight:bold"});
    columns.Bound(c => c.FacilityType).Title("Type").HeaderHtmlAttributes(new {style = "white-space: normal;font-weight:bold"}).MinScreenWidth(70).HtmlAttributes(new {style = "font-weight:bold"});
    columns.Bound(c => c.FacilityUse).Title("Use").HeaderHtmlAttributes(new {style = "white-space: normal;font-weight:bold"}).MinScreenWidth(70).HtmlAttributes(new {style = "font-weight:bold"});
    columns.Bound(c => c.FacilityStatus).Title("Status").HeaderHtmlAttributes(new {style = "white-space: normal;font-weight:bold"}).MinScreenWidth(70).HtmlAttributes(new {style = "font-weight:bold"});
    columns.Bound(c => c.FacilityOwnerShip).Title("OwnerShip").HeaderHtmlAttributes(new {style = "white-space: normal;font-weight:bold"}).MinScreenWidth(70).HtmlAttributes(new {style = "font-weight:bold"});
    columns.Bound(c => c.FacilitySystemPlan).Title("System Plan").HeaderHtmlAttributes(new {style = "white-space: normal;font-weight:bold"}).MinScreenWidth(70).HtmlAttributes(new {style = "font-weight:bold"});
    columns.Bound(c => c.FacilityCounty).Title("County").HeaderHtmlAttributes(new {style = "white-space: normal;font-weight:bold"}).HtmlAttributes(new {style = "font-weight:bold"});
    .ToolBar(tools => tools.Excel().Text("<i class='sprite excel' title='Export to Excel'></i>").HtmlAttributes(new {style = "background-color:Transparent"}))
    .HtmlAttributes(new {style = "height: 490px"})
    .Excel(excel => excel.FileName("FacilitiesList-" + DateTime.Now.Date + ".xlsx").Filterable(true).ProxyURL(Url.Action("Excel_Export_Save", "AdminMain", new {area = "Admin"})).ForceProxy(true).AllPages(true))
    .DataSource(dataSource => dataSource
    .Read(read => read.Action("SearchFacilities", "AdminMain", new {area = "Admin"}).Data("GetParameters"))
    ) )

    Child Grid:

    <script id="template" type="text/kendo-tmpl">
    .Columns(columns =>
    columns.Bound(c => c.ContactName).Title("Person Name").HeaderHtmlAttributes(new { style = "white-space: normal;font-weight:bold;" }).MinScreenWidth(80).HtmlAttributes(new { style = "color:blue;font-weight:bold" });
    columns.Bound(c => c.FunctionName).Title("Function/Group Name(s)").HeaderHtmlAttributes(new { style = "white-space: normal;font-weight:bold" }).MinScreenWidth(60).Encoded(false).ClientTemplate("\\#= getHtmlNewLinesString(FunctionName) \\#").HtmlAttributes(new { style = "font-weight:bold" });
    columns.Bound(c => c.CompanyName).Title("Company Name").HeaderHtmlAttributes(new { style = "white-space: normal;font-weight:bold" }).MinScreenWidth(60);
    columns.Bound(c => c.ContactId).Hidden(true);
    .HtmlAttributes(new { style = "height: 120px;width:600px" })
    .DataSource(dataSource => dataSource
    .Read(read => read.Action("GetContactsList", "Contacts",new { facilityId = "#=FacilityId#" }))


    I would appreciate your help.

  2. Viktor Tachev
    Viktor Tachev avatar
    2501 posts

    Posted 19 Jan 2017 Link to this post

    Hello Rizwan,

    Please refer to the example below that illustrates how you can export hierarchical Grid data ti Excel. Give the approach a try and let me know how it works for you.

    Viktor Tachev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top