Hi, I am working on template grid with export function, but when I click export, I see that particular image column is showing URL instead of picture. I am wondering is there any built-in function that allows the conversion or do I need to convert that image into base64 so that image can be shown after export.
This is my code :
var gridObj = document.getElementById("AttendanceGrid").ej2_instances[0];
var selected = gridObj.getSelectedRecords();
if (args.item.id === 'PrintProfileBtn') {
gridObj.print();
} else if (args.item.id === 'ExportexcelBtn') {
var excelExportProperties = {
fileName: "AttendanceGrid.xlsx"
};
gridObj.excelExport(excelExportProperties);
} else if(args.item.id === 'ExportpdfBtn') {
var pdfExportProperties = {
fileName: "AttendanceGrid.pdf"
};
gridObj.pdfExport(pdfExportProperties);
}
Any helps will be appreciated, thanks
|
<script>
// Grid's toolbarClick event
function toolbarClick(args) {
var gridObj = document.getElementById("Grid").ej2_instances[0];
if (args.item.id === 'Grid_pdfexport') {
gridObj.pdfExport();
}
}
//When you display the image in Grid to column, you need to convert this base64 string to image. We suggest you to use queryCellInfo event of the Grid to achieve this requirement.
function queryCellInfo(args) {// Grid's queryCellInfo event
if (args.column.field == "Image") {
args.cell.querySelector('img').setAttribute('src', 'data:image/jpeg;base64 ,' + args.data.Image);
args.cell.querySelector('img').setAttribute('width', 150);
args.cell.querySelector('img').setAttribute('height', 150);
}
}
// Grid's pdfQueryCellInfo event
function pdfQueryCellInfo(args) {
if (args.column.headerText == 'Image') {
args.value = new ej.pdfexport.PdfBitmap(args.data.Image); // pass base64 of jpeg
for (var i = 0; i < args.cell.gridRow.pdfGrid.rows.rows.length; i++) {
args.cell.gridRow.pdfGrid.rows.getRow(i).height = "50"; //set height
}
}
}
</script> |