cancel
Showing results for 
Search instead for 
Did you mean: 

Formatting Date Column in Smart Table Export to Spreadsheet

INC02778
Discoverer
0 Kudos
112

Hi everyone,

I'm currently working with the export functionality of a Smart Table, where I need to download the table data as a spreadsheet. There's a specific column called "Due Date" that receives data from the backend in the yyyymmdd format (e.g., 20240630) which I am getting in string type. For displaying this in the table, I use a formatter to convert it to dd/mm/yyyy format (e.g., 30/06/2024).

However, when exporting the data, the spreadsheet still contains the date in the yyyymmdd format. I would like to format the data to dd/mm/yyyy before exporting it to the spreadsheet.

Can anyone provide guidance on how to achieve this?

Thanks in advance!
SAPUI5

Accepted Solutions (1)

Accepted Solutions (1)

INC02778
Discoverer
0 Kudos

Thank you @junwu

I have implemented your suggested solution with additional enhancements. We utilize the `beforeExport` event of the smart table to call a function that sets the properties and formatting of the values. Here is the implemented solution.

onBeforeExport: function(oEvent) {
            var oExportSettings = oEvent.getParameter("exportSettings");
            var aColumns = oExportSettings.workbook.columns;

            var iDueDateColumnIndex = aColumns.findIndex(function (oColumn) {
                return oColumn.property === "DueDate";
            });
           
            if (iDueDateColumnIndex !== -1) {
                aColumns[iDueDateColumnIndex] = {
                    label: 'Due Date',
                    type: 'string',
                    property: 'DueDate',
                    inputFormat: "([0-9]{4})([0-9]{2})([0-9]{2})",
                    template: "{2}/{1}/{0}",
                    width: 10
                };
            }
        }

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

use this when you build the spreadsheet

{
label: 'DateString',
type: EdmType.Date,
property: 'SampleDateString',
inputFormat: 'yyyymmdd',

format:'dd/mm/yyyy'
width: 25
}