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

Kendo Grid - export to excel with grouping

4 Answers 885 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kirubakaran
Top achievements
Rank 1
Kirubakaran asked on 14 May 2020, 09:19 AM

This is my code

1. I want to export master & its related child record to excel and its working fine if i didnt use grouping. but whereas if i add grouping, then its not working. 

2. Also how to remove the header in child records while exporting to excel.

Expecting your help.

4 Answers, 1 is accepted

Sort by
0
Silviya Stoyanova
Telerik team
answered on 18 May 2020, 09:19 AM

Hello  Kirubakaran,

Thank you for the provided code.

As you could see from the following Demo Excel Export with grouping is available out of the box. From your code, I saw you are also using custom logic for exporting Grid with detailed templates, which as you know is not supported and it is a known limitation - https://docs.telerik.com/kendo-ui/controls/data-management/grid/export/excel-export#known-limitations.

The problem with the above combination is the data structure. It changes depending on if it has group items or not. With group:

 

masterData[rowIndex].CommentsDescription   //gets "undefined"

 

This means that you will need to modify the custom implementation to get the CommentsDescription content. For instance, something like that:

for (var rowIndex = 0; rowIndex < masterData.length; rowIndex++) {
                    var detail = masterData[rowIndex].CommentsDescription ? masterData[rowIndex].CommentsDescription : masterData[rowIndex].items.map(x=>x.CommentsDescription).join(' ');
                  exportChildData(detail, rowIndex);
}

I hope that would help you to move forward with the customization.

Kind Regards,
Silviya Stoyanova
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 19 May 2020, 05:24 AM

Here is my updated code.

As per your guidance i did few changes and just one issue i am facing.

As you can see in my coding, i applied two for-loops and processed. Here i am not able to skip the group header in my for-loop, due to that the child rows are placing a row upwards (which is incorrect).

How can i find the group header row and skip it to achieve my output?

Looking forward your help on this.

0
Kirubakaran
Top achievements
Rank 1
answered on 19 May 2020, 11:50 AM

Silviya Stoyanova,

I found the answer and updated the code to skip the group header in for-loop  :)

Expecting just one solution now.I want to show my Child records below "Comments" column.

Looking forward your help on this.

 

0
Silviya Stoyanova
Telerik team
answered on 20 May 2020, 01:17 PM

Hello  Kirubakaran,

I am glad to read you gain progress.

Every row has its type field

  • "header"
  • "footer"
  • "group-header"
  • "group-footer"
  • "data"

So you could find the group-header row like that:

var sheet = e.workbook.sheets[0];
var row = sheet.rows[rowIndex];
           
    if(row.type =="group-header"){
                  //your code

 

To place the description under the Comment column you need to prepend enough cells:

// Prepend empty cells to each row.
for (var ci = 0; ci < sheet.rows.length; ci++) {
                      if (sheet.rows[ci].cells[0].value) {
                        sheet.rows[ci].cells.unshift({},{},{},{},{});
                      }
 }                

 

Kind Regards,
Silviya Stoyanova
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
Silviya Stoyanova
Telerik team
Kirubakaran
Top achievements
Rank 1
Share this question
or