How to customize the Grid cell values while exporting in JavaScript?
You can customize the default cell values before excel exporting the JavaScript Grid by using the “excelHeaderQueryCellInfo” and “excelQueryCellInfo” events. You can do the same for pdf export by using the “pdfHeaderQueryCellInfo” and “pdfQueryCellInfo” events.
This is demonstrated in the below sample code in which the header and content cell values are customized before exporting using the corresponding query cell info events.
JS
exportQueryCellInfo = function(args) { if (args.name == 'excelHeaderQueryCellInfo' || args.name =='pdfHeaderQueryCellInfo') { console.log(args.cell.value); // here you can get header cell value if (args.cell.value == 'Order ID') { args.cell.value = 'Changed'; } } if (args.name == 'excelQueryCellInfo' || args.name == 'pdfQueryCellInfo') { console.log(args.value); // here you can get content cell value if (args.value == 'VINET') { args.value = 'Changed'; } } }; var grid = new ej.grids.Grid({ dataSource: window.orderDatas, allowExcelExport: true, allowPdfExport: true, excelQueryCellInfo: exportQueryCellInfo, excelHeaderQueryCellInfo: exportQueryCellInfo, pdfQueryCellInfo: exportQueryCellInfo, pdfHeaderQueryCellInfo: exportQueryCellInfo, toolbar: ['ExcelExport', 'PdfExport', 'CsvExport'], columns: [ { field: 'OrderID', headerText: 'Order ID', width: 120, textAlign: 'Right', }, { field: 'CustomerID', headerText: 'Customer ID', width: 150 }, { field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right', }, { field: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }, ], }); grid.appendTo('#Grid'); grid.toolbarClick = function(args) { if (args.item.id === 'Grid_pdfexport') { grid.pdfExport(); } if (args.item.id === 'Grid_excelexport') { grid.excelExport(); } if (args.item.id === 'Grid_csvexport') { grid.csvExport(); } };
OUTPUT
Conclusion
I hope you enjoyed learning about how to customize the Grid cell values while exporting.
You can refer to our JavaScript Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Grid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!