Akash
Akash

Reputation: 4612

Ag-grid - Exported excel does not parse string to date format in IE

I am exporting ag-grid data to excel which has few date type columns. On opening exported file, I observed that date type columns are not auto-formatted to 'Date' format when exported from IE. Same thing works fine in Chrome.Below is the code which formats the date string -

exportData: function() {
        var vm = this;
        var params = {
            fileName : vm.pageTitle + '.csv',
            processCellCallback  : function(params) { 
             if (params.value) {
                 if(params.column.colId === "endDate" || params.column.colId === "startDate"){
                    return params.value.toLocaleDateString();
                 }
             }
             return params.value;
            }
        };
        vm.gridOptions.api.exportDataAsCsv(params);     
    }

Below is the excel screenshot for IE - The General format should be Date

enter image description here

Thanks in advance for any help.

Upvotes: 1

Views: 3184

Answers (1)

Jarod Moser
Jarod Moser

Reputation: 7348

According to this question, toLocaleDateString() behaves funky in IE. My guess is that it is adding a zero width character. I guess this because I have used the zero width character to force formatting in excel as general (my use case was 1/1 needed to stay that way and not transform to 1-jan like excel wanted to do)

So to solve your problem, you could either format the date yourself to ensure what characters are getting placed, or you could regex out any whitespace characters with:

.toLocaleDateString().replace(/\s/g,'')

Upvotes: 2

Related Questions