Reputation: 61
when I try to export the excel from Kendo grid, the date format is incorrect.
This Warranty_Start_Date is nullable in my table column, and below is the template for grid's column.
customColumns.push({
title: customHeaders[i],
field: headers[i],
width: 150,
template:
"#= " + headers[i] + " ? kendo.toString(kendo.parseDate(" + headers[i] + "), 'dd/MM/yyyy') : 'N/A' #",
});
and for the grid, I enable the excel export function and trying to customize the format for certain column:
var grid = $("#gridHardwares").kendoGrid({
excel: {
fileName: "excelfile.xlsx",
allPages: true,
filterable:true
},
excelExport: function(e) {
var sheet = e.workbook.sheets[0];
for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
var row = sheet.rows[rowIndex];
for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex ++) {
if (cellIndex >= 9 && cellIndex <= 11)
{
row.cells[cellIndex].format = "yy-MM-dd hh:mm:ss";
}
if (cellIndex >= 13)
row.cells[cellIndex].format = "0.00";
}
}
},
I don't understand because this two decimal places format is working fine but the date format is not. The export result in excel: date is not in readable format
I also tried this method where it keeps the column template, but I hit an error for "replace undefined"
excelExport: function(e) {
var sheet = e.workbook.sheets[0];
var template = kendo.template(this.columns[13].template);
for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
var row = sheet.rows[rowIndex];
for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex ++) {
if (cellIndex >= 9 && cellIndex <= 11)
{
var dataItem = {
Warranty_Start_Date: row.cells[13].value
};
row.cells[13].value = template(dataItem);
row.cells[cellIndex].format = "yy-MM-dd hh:mm:ss";
}
if (cellIndex >= 13)
row.cells[cellIndex].format = "0.00";
}
}
},
Maybe this template method is not suitable in my case, I don't know. But is there any other ways to convert this date string /Date(1382544000000)/ into proper "dd-MM-yyyy" format? Need help badly :(
Upvotes: 3
Views: 5432
Reputation: 61
ok fine, the solution is just setting this field type to "date". Crazy.
Upvotes: 2