Hi Team,
In normal grid, we had one of the columns as DATE which was not getting exported properly. We were getting NaN in excel sheet. But the issue is fixed now.
Following/Highlighted code we modified to get it proper in excel sheet.
var exportingIndicator = $('<div>');
$('#exportButton').on('click', function () {
// $("#loaderModal").modal('show');
var gridExcelExporter = new $.ig.GridExcelExporter();
var $grid = $('#csagrid');
gridExcelExporter.exportGrid($grid, {
fileName: "CSAReport",
gridStyling: "applied"
}, {
exportStarting: function (e, args) {
showExportingIndicator(args.grid, exportingIndicator);
},
cellExported: function (e, args) {
if (args.xlRow.index() == 0) {
return;
}
if (args.columnIndex == 2) { // columnIndex 2 because date column is at index 2
var rowIndexValue = e._xlRowIndex - 1;
var colCellValue = e._dataSource._data[rowIndexValue].ENTRY_DATE;
var val = formatDate(colCellValue);
args.xlRow.setCellValue(args.columnIndex, val);
success: function () {
// $("#loaderModal").modal('hide');
hideExportingIndicator(exportingIndicator);
});
----------------------------------------------------------------------------------------
And this function –
function formatDate(date) {
var d = new Date(parseInt((date).match(/\d+/)[0]));
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [month, day, year].join('/');
----------------------------------------------------------------------------------------------------------------------------------------
But, we are not able to get the same DATE column when it is a hierarchical grid.
ENTRY_DATE column is in the child grid. How do we modify our existing code(code for getting date in proper format after exporting to excel) for hierarchical grid?
Hello Tapas,
Thank you for posting in our community.
My suggestion is to pass the exposed cellValue property of the argument args to the formatDate function:
//... cellExported: function (e, args) { if (args.xlRow.index() == 0) { return; } if (args.columnIndex == 2) { // columnIndex 2 because date column is at index 2 var val = formatDate(args.cellValue); args.xlRow.setCellValue(args.columnIndex, val); } } //....
any update on the same.