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

Items added to bound datasource don't appear in Excel export

3 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phyl
Top achievements
Rank 1
Phyl asked on 21 Nov 2014, 02:12 PM
Hi all,

I just encountered a problem that I was not yet able to solve when I was playing around with the Excel export.

In our application there is a view in which we use a grid for data visualization. The grid itself is bound to a datasource within our viewmodel which is also used for filling a listview in another subview. The datasource gets new items pushed from the server or injected from different sources - there is no transport defined. Everything works fine except the Excel export as new items are missing within the export :(..

Here is a litte JSFiddle -> http://jsfiddle.net/ac495x2h/

What am I missing / doing wrong in order to have the added items included in the exported file? (already tried pushCreate and setting a whole new data array too)

3 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 21 Nov 2014, 10:26 PM
Yeah, I bumped into this as well.  It appears that the initial data-source set on the grid is immediately captured by the excel export feature.  There may be a better way but I just utilized the "excelExport" event handler of the grid and rebuilt the worksheet being exported.  Reference the excel export api from here Events excelExport which will lead you to The Workbook API so you'll know how to construct the workbook at button click.

excelExport: function(e){
  var excelRows, excelCells, record;
 
  //build header row
  excelCells = [];
  excelCells.push({ value: "Car" });
  excelCells.push({ value: "Year" });
 
  excelRows = [];
  //iterate thru dataset
  for (var i = 0; i < dataArray.length; i++) {
    record = dataArray[i];
    excelCells = [];
    excelCells.push({ value: record["car"] });
    excelCells.push({ value: record["year"] });
 
    excelRows.push({ cells: excelCells });
  }
 
  e.workbook.sheets[0].rows = excelRows;
}

This worked for me, hopefully it will for you too.
0
Chris
Top achievements
Rank 1
answered on 21 Nov 2014, 10:29 PM
Oops, forgot to add

excelRows.push( { cells: excelCells });

at the end of the //build header row section.
0
Phyl
Top achievements
Rank 1
answered on 24 Nov 2014, 08:46 AM
Awesome. I was able to solve it with your approach! Thank You very much :-)
Tags
Grid
Asked by
Phyl
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Phyl
Top achievements
Rank 1
Share this question
or