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

Exporting more columns than displayed

1 Answer 699 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 22 Mar 2019, 12:29 PM
Currently I display a grid that has X columns. I export it to Excel and it also exports X columns. How do I export Y columns and still only display X columns? Or export different columns than displayed? This would be for a "normal" grid and one that is grouped.

1 Answer, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 26 Mar 2019, 09:55 AM
Hi, Kevin,

By default, the Kendo UI Grid excel export includes only visible columns in the export. 

There are a few approaches that you can take to accomplish the desired result:

1) Add the columns to the definition as hidden and show them during the excel export as demonstrated in this article:

https://docs.telerik.com/kendo-ui/knowledge-base/grid-include-hidden-columns-in-excel-export

2) Intercept the excelExport event and build your own workbook 

https://dojo.telerik.com/@bubblemaster/ACUzeHep

excelExport: function(e){
  var sheet = e.workbook.sheets[0];
  var data = e.data;
  var columns = Object.keys(data[0].toJSON()).map(function(col){
    return {
      value: col,
      autoWidth:true,
      background: "#7a7a7a",
      color: "#fff"
    };
  });
 
  var rows = [{cells:columns, type: "header"}];
 
  for (var i = 0; i < data.length; i++){
    var rowCells = [];
    for(var j=0;j < columns.length;j++){
      var cellValue = data[i][columns[j].value];
      rowCells.push({value: cellValue});
    }
    rows.push({cells: rowCells, type: "data"});
  }
  sheet.rows = rows;
}
 
3) Add a custom button and create your own dataSource export:

https://docs.telerik.com/kendo-ui/framework/excel/extract-datasoruce

Let me know in case you have further questions regarding your preferred approach.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Share this question
or