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

Kendo Export to excel Need to display detail grid column in comma separated values in excel in main grid excel export

1 Answer 419 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Veteran
Mohammed asked on 19 Jun 2020, 01:22 PM

Hi 

I Have a main grid and detail grid like this

https://docs.telerik.com/kendo-ui/knowledge-base/grid-excel-export-hierarchy-master-and-detail-separate-sheets

i need to have the detail grid column values separated in comma in another new  columns in excel in the same row of can you please help on this.

 

Thanks

Mohammed

 

 

1 Answer, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 23 Jun 2020, 12:57 PM

Hello, Mohammed,

To add the detail values in a separate column where their object values are comma separated, a much simpler approach can be taken.

As in the provided link:

  • read the child grid data sources beforehand so they are all available
  • in the excelExport event handler, add an additional header column cell
  • loop the rows and push the details that correspond to the current master row in a new cell

excelExport: function(e) {
          var rows = e.workbook.sheets[0].rows;       
          var masterData = e.data;

          // add column header
          rows[0].cells.push({
            type: "header",
            value: "Details",
            background:"#7a7a7a",
            color: "#fff", 
            colSpan: 1,
            rowSpan: 1
          });

          for (var rowIndex = 1; rowIndex < rows.length; rowIndex++) {
            var masterID = e.data[rowIndex-1].EmployeeID;
            var details = dataSource.data().filter(x=>x.EmployeeID == masterID);

            var csv = details.map(function(d){
              return Object.values(d.toJSON()).map(function(i){ if(typeof(i)!=="object"){return i}}).filter(x=>x).join();
            });

            rows[rowIndex].cells.push({
              value:csv[0] // I added only the first detail here as our example has a huge amount of details
            })
          }
        },

Here is a runnable example for your reference:

http://dojo.telerik.com/iduhadIx

Regards,
Alex Hajigeorgieva
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
Mohammed
Top achievements
Rank 1
Veteran
Answers by
Alex Hajigeorgieva
Telerik team
Share this question
or