date changes on export kendoGrid

2019-06-06 00:14发布

I have this table made with kendoUI, When user export the table to excel, all dates values change, the issue appears only in chrome, firefox works fine.

issue

You can try the runnable on this link

var localData=[
    {cliente:'COMERCIALIZACION',lote:1323,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:10},            {cliente:'COMERCIALIZACION',lote:1324,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:80},{cliente:'COMERCIALIZACION',lote:1325,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:29},                {cliente:'COMERCIALIZACION',lote:1326,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:5}];

1条回答
SAY GOODBYE
2楼-- · 2019-06-06 00:37

The problem is most likely caused by difference in time zones. The timezone of the browser is used automatically.
Try adding HH:mm to the format of the date in grid and also display the time in the Excel sheet and check the time difference.

Edit:
If you're interested only in the date and not the time, you can set the hours component of the date to 12 and that way even if the difference is several hours, the date will remain the same.

You can use the following code to do this:

excelExport: (e) => {
    console.log("Excel export", e.workbook);

    e.workbook.sheets[0].rows.filter((row) => row.type === "data").forEach((row, index) => {
        row.cells[2].value.setHours(12);
    });

    console.log("Excel export", e.workbook);
}

If you want to use a more generic approach and not the index of the column with the date, you can do it like this:

e.workbook.sheets[0].rows.filter((row) => row.type === "data").forEach((row, index) => {
    row.cells.filter((cell) => cell.value instanceof Date).forEach((cell) => cell.value.setHours(12));
});
查看更多
登录 后发表回答