date changes on export kendoGrid

冷暖自知 提交于 2019-12-07 02:43:27

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));
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!