This is a migrated thread and some comments may be shown as answers.

Grid Export to excel - Child rows not exporting

5 Answers 782 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kirubakaran
Top achievements
Rank 1
Kirubakaran asked on 08 Apr 2020, 06:40 AM

Here is my code. When i am exporting, child rows are not  getting exported. How to achieve this. Expecting your help.

 

<script type="text/javascript">
        $(document).ready(function () {
                        $("#btnExportToExcel").click(function (e) {
                    var grid = $("#grid").data("kendoGrid");
                    grid.saveAsExcel();
                });
        });
    </script>

<div id="grid"></div>
                    <button id="btnExportToExcel" type="submit" name="excel" value="valexcel">
                        <img src="images/excel-icon.png" alt="imageExcel" /></button>
<script> $("#grid").kendoGrid({ columns: [{ field: "productName" }, { field: "category" }, { field: "status" }, { field: "Comments" }], dataSource: { data: [{ productName: "Tea", category: "Beverages", status: "Open", "Comments": "" }, { productName: "Coffee", category: "Beverages", status: "Open", "Comments": "comment1" }, { productName: "Ham", category: "Food", status: "Open", "Comments": "" }, { productName: "Bread", category: "Food", status: "Open", "Comments": "" }, { productName: "Hammer", category: "Hardware", status: "Closed", "Comments": "Comment test" }, { productName: "Screw", category: "Hardware", status: "Open", "Comments": "commenting testing" }], group: { field: "category" } },  detailTemplate: "<div class='Comments'>",
                    detailInit: function (e) { e.detailRow.find(".Comments").html("<p>" + e.data.Comments + "</p>"); }, });</script>

5 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 09 Apr 2020, 08:23 PM

Hello Kirubakaran,

See the following KB article, which demonstrate how the excelExport event can be used to export the master Grid and its detail Grids to Excel: https://docs.telerik.com/kendo-ui/knowledge-base/detail-grid-export

Regards,
Ivan Danchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Kirubakaran
Top achievements
Rank 1
answered on 13 Apr 2020, 12:58 PM

Hello Ivan,

Based on the link which you shared I tried. But i cannot achieve the output. Can you/anyone help me out. Attached code

0
Ivan Danchev
Telerik team
answered on 15 Apr 2020, 11:43 AM

Kirubakaran,

The dojo example you linked was missing some tags: <html>, <head>, <body>, so I added them and the data in the detail grids is exported. See the modified example here: https://dojo.telerik.com/OmezAJoy

Regards,
Ivan Danchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Kirubakaran
Top achievements
Rank 1
answered on 15 Apr 2020, 01:39 PM

Ivan,

Currently the grid whichever showing the value is the correct one. And that need to be exported to excel with child rows.

For that i added the export to excel coding and it gave wrong output.Kindly refer my 1st post. That records need to be exported to excel. As that records have detailTemplete and dependancy, i am not aware of exporting those informations.

So my ultimate aim is to export the grid (my 1st thread in this post).

Expecting your help on this

0
Accepted
Veselin Tsvetanov
Telerik team
answered on 17 Apr 2020, 09:12 AM

Hi Kirubakaran,

Thank you for the further explanation provided.

As in your scenario, you do not have a detail Grid in the detail row, but at the same time you have grouping enabled, you will need to slightly alter the suggested implementation in the KB article. Here is how I would suggest you to implement the handler in order to copy the value of the comments field on a new line below the actual item:

excelExport: function(e) {
  e.preventDefault();

  var workbook = e.workbook;
  var rows = workbook.sheets[0].rows;
  
  workbook.sheets[0].columns.unshift({
    width: 30
  });

  for (var i = 0; i < rows.length; i++) {
    var row = rows[i];

    if(row.type === "data") {
      rows.splice(i + 1, 0, { type: "detail", cells: [{},{},{ value: row.cells[4].value }]});
    }
  }

  kendo.saveAs({
    dataURI: new kendo.ooxml.Workbook(workbook).toDataURL(),
    fileName: "Export.xlsx"
  });
},

Attached you will find the full implementation of the above scenario, based on the Dojo previously sent. Keep in mind that the suggested approach may need some further adjustments according to your specific requirements.

Regards,
Veselin Tsvetanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Kirubakaran
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Kirubakaran
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or