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

    Hi
    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:
    @(Html.Kendo().Grid<INDOT.SOARS.ViewModels.Models.SearchFacilitiesListViewModel>()
    .Name("gvFacilitiesReport")
    .AutoBind(false)
    .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"}))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new {style = "height: 490px"})
    .ClientDetailTemplateId("template")
    .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
    .Ajax()
    .PageSize(100)
    .Read(read => read.Action("SearchFacilities", "AdminMain", new {area = "Admin"}).Data("GetParameters"))
    ) )

    Child Grid:

    <script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<INDOT.SOARS.ViewModels.Models.ContactDetailsViewModel>()
    .Name("gv_#=FacilityId#")
    .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);
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height: 120px;width:600px" })
    .DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(5)
    .Read(read => read.Action("GetContactsList", "Contacts",new { facilityId = "#=FacilityId#" }))
    )

    .ToClientTemplate()
    )
    </script>

    I would appreciate your help.
    Thanks
    Rizwan

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2499 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.



    Regards,
    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