Skip to content

Commit

Permalink
fix(excel): exporting to Excel should also work from Grid Menu
Browse files Browse the repository at this point in the history
- also fixed the onGridBeforeExportToExcel & After Event Emitters
  • Loading branch information
ghiscoding-SE committed Oct 17, 2019
1 parent db8273e commit b2f0680
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/app/examples/grid-grouping.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ <h2>{{title}}</h2>
[gridOptions]="gridOptions"
(onGridBeforeExportToFile)="processing = true"
(onGridAfterExportToFile)="processing = false"
(onGridBeforeExportToExcel)="processing = true"
(onGridAfterExportToExcel)="processing = false"
(onAngularGridCreated)="angularGridReady($event)">
</angular-slickgrid>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
@Output() onGridStateChanged = new EventEmitter<GridStateChange>();
@Output() onGridBeforeExportToFile = this.exportService.onGridBeforeExportToFile;
@Output() onGridAfterExportToFile = this.exportService.onGridAfterExportToFile;
@Output() onGridBeforeExportToExcel = new Subject<boolean>();
@Output() onGridAfterExportToExcel = new Subject<any>();
@Output() onGridBeforeExportToExcel = this.excelExportService.onGridBeforeExportToExcel;
@Output() onGridAfterExportToExcel = this.excelExportService.onGridAfterExportToExcel;
@Input() customDataView: any;
@Input() gridId: string;
@Input() gridOptions: GridOption;
Expand Down Expand Up @@ -339,10 +339,6 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn

// if Excel Export is enabled, initialize the service with the necessary grid and other objects
if (this.gridOptions.enableExcelExport && this.sharedService) {
// create an instance of the ExcelExportService only when required (opt-in)
this.excelExportService = new ExcelExportService(this.translate);
this.onGridBeforeExportToExcel = this.excelExportService.onGridBeforeExportToExcel;
this.onGridAfterExportToExcel = this.excelExportService.onGridAfterExportToExcel;
this.excelExportService.init(this.grid, this.dataView);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class ExcelExportService {
// -----------------------

private getDataOutput(): string[][] | ExcelCellFormat[][] {
const columns = this._grid.getColumns() || [];
const columns = this._grid && this._grid.getColumns && this._grid.getColumns() || [];

// data variable which will hold all the fields data of a row
const outputData = [];
Expand Down Expand Up @@ -228,7 +228,7 @@ export class ExcelExportService {

// get grouped column titles and if found, we will add a "Group by" column at the first column index
// if it's a CSV format, we'll escape the text in double quotes
const grouping = this._dataView.getGrouping();
const grouping = this._dataView && this._dataView.getGrouping && this._dataView.getGrouping();
if (grouping && Array.isArray(grouping) && grouping.length > 0) {
this._hasGroupedItems = true;
return groupByColumnHeader;
Expand Down Expand Up @@ -274,7 +274,7 @@ export class ExcelExportService {
* Get all the grid row data and return that as an output string
*/
private pushAllGridRowDataToArray(originalDaraArray: string[][], columns: Column[]): string[][] | ExcelCellFormat[][] {
const lineCount = this._dataView.getLength();
const lineCount = this._dataView && this._dataView.getLength && this._dataView.getLength();

// loop through all the grid rows of data
for (let rowNumber = 0; rowNumber < lineCount; rowNumber++) {
Expand Down

0 comments on commit b2f0680

Please sign in to comment.