As we have feature for other charts to download JPEG,PNG and SVG.
How to download JPEG,PNG and SVG for ejs-grid?
Hi Praveenkumar,
Like in syncfusion chart we have options to print in different format using code,
args.chart.exportModule.export('PNG', 'export');
args.chart.exportModule.export('SVG', 'export');args.chart.exportModule.export('JPEG', 'export');
args.chart.exportModule.export('PDF', 'export');https://ej2.syncfusion.com/angular/documentation/chart/chart-print/
Like this how we can export ejs-grid chart in JPEG,PNG,SVG format.
|
"dependencies": {
. . .
"@angular/core": "12.1.0",
. . .
"@syncfusion/ej2-angular-base": "19.2.55",
. . .
"@syncfusion/ej2-grids": "19.2.56",
. . .
"html2canvas": "^1.3.2",
|
|
<div>
<select name="selectIndex" class='e-cus' autocomplete="off" id="exporttype" >
<option value="JPEG" >JPEG</option>
<option value="PNG">PNG</option>
</select>
<button ejs-button class="e-control e-btn e-lib e-info e-cus" (click)='downloadImage($event)' id="togglebtn">EXPORT</button>
</div>
<ejs-grid #grid [dataSource]='data' allowPaging='true' [pageSettings]='pageSettings' [toolbar]='toolbar'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right'></e-column>
. . .
</e-columns>
</ejs-grid>
<div id="download">
<img #canvas>
<a #downloadLink></a>
</div>
</div>
|
|
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { data } from './data';
. . .
import html2canvas from 'html2canvas';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public data: Object[];
public pageSettings: Object;
public canvasImg: any;
@ViewChild('grid') grid: GridComponent;
@ViewChild('canvas') canvas: ElementRef;
@ViewChild('downloadLink') downloadLink: ElementRef;
ngOnInit(): void {
this.data = data.slice(0, 30);
this.pageSettings = { pageCount: 5 };
//this.canvasImg = html2canvas();
}
downloadImage(eve) {
this.grid.showSpinner();
const gObj: GridComponent = this.grid;
const element1: HTMLElement = createElement('div', {
id: this.grid.element.id + '_cus',
className: gObj.element.className + ' e-cus-grid'
});
element1.classList.remove('e-gridhover');
document.body.appendChild(element1);
const gridObj: any = new Grid({
dataSource: this.grid.dataSource,
columns: this.grid.columns,
allowPaging: false,
query: this.grid.getQuery(),
dataBound: function(args) {
html2canvas(gridObj.element, {
// width: 3000,
// height: 3000
}).then(canvas => {
this.canvas.nativeElement.src = canvas.toDataURL();
let exportType = document.getElementById('exporttype').value;
this.downloadLink.nativeElement.rel='nofollow' href = canvas.toDataURL(
'image/' + exportType
);
this.downloadLink.nativeElement.download = 'tbl.' + exportType;
this.downloadLink.nativeElement.click();
gridObj.destroy();
document.getElementById(this.grid.element.id + '_cus').remove();
this.grid.hideSpinner();
});
}.bind(this)
});
gridObj.appendTo(element1);
}
}
|