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

2 posts, 0 answers
  1. Mohammed
    Mohammed avatar
    26 posts
    Member since:
    May 2020

    Posted 19 Jun 2020 Link to this post

    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

     

     

  2. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1082 posts

    Posted 23 Jun 2020 Link to this post

    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.
Back to Top