NitinSingh
NitinSingh

Reputation: 2068

Exporting multiple grids to single excel in Infragistics ignite grid

I have multiple Ignite UI grids setup on a page. The grid has excel export feature but it only works for the current grid. How can I export all the grids at a single event? Any grid events to be captured or modified. I am using 2016 v2 release

Upvotes: 1

Views: 468

Answers (1)

NitinSingh
NitinSingh

Reputation: 2068

After researching for multiple options, found a solution which does a sequential walk through of the grid collection and appends each one to the main workbook.

For exportEnding method of 1st grid you chose, call a function which does the export (suppose to) for the 2nd grid. This can be sequenced for as many grids as required. Let say each such function is named as ExportGrid, eg exportSecondGrid.

grid1's

    exportEnding :function(sender, args) {
    exportSecondGrid(args.workbook);
    return false; 
    }

Use the grid 2's headerExporting event to append the current worksheet to the main workbook. Its exportEnding takes the header collection generated in header exporting to manually set for the worksheet

Now the grid 2's events as below

var headerArr = [];
$.ig.GridExcelExporter.exportGrid($("#gridSecond"), {
    fileName: fileNamePassedAsParameter,
    worksheetName: Sheet2NamePassedAsParameter
},
{ 
headerCellExporting: function(sender, args) {
    // We will save all the headers coming to our array for retrieval later on
    headerArr.push(args.headerText);
    if (args.columnIndex === 0) { 
        sender._workbook = workbook;
        sender._workbook.worksheets().add( sender._worksheet.name());
        sender._worksheet = sender._workbook.worksheets(1);
    } 
}, 
exportEnding: function(sender, args) { 
    // Now use the array of headers to be updated
    var row = sender._worksheet.rows(0);
    for(var ind=0; ind < headerArr.length; ind++) {
        row.setCellValue(ind, headerArr[ind]); 
    }
}
}
);
}

Upvotes: 4

Related Questions