[Data Grid] Data grid Date field giving incorrect dates

Forge Component
(38)
Published on 3 Aug (6 days ago) by OutSystems R&D
38 votes
Published on 3 Aug (6 days ago) by OutSystems R&D

Hi All, 

Data Grid Component- Date Field 

I have a data grid showing few columns, few of them are Date fields. The issue I'm facing currently is that the date fields are displaying values, which is one day less than the actual date available. The entity saves the correct date as per the source, the REST call fetching and mapping the data to the grid has the correct date. The issue is only when it is displayed. Anyone has faced such an issue before. Please help me in this regard.


Thanks and Regards,

Priya 

Hi Priyadharshini!

Try looking into this topic. It has some of the approaches that could help you solve that.

https://www.outsystems.com/forums/discussion/53172/date-time-results-are-being-modified/


Kind regards,
Joseph Enriquez

Hi, Priya.

We've noticed the same thing as well.

There is a date format you can set for the column. If you choose 'r' or 'R', you will get back the proper date, BUT the formatting will be fully expanded UTC time, which is not the best. Still looking for a solution ourselves.

e.formatDate = function(n, r) {
            switch (n = t.asDate(n),
            r) {
            case "r":
            case "R":
                return n.toUTCString();
            case "u":
                return n.toISOString().replace(/\.\d{3}/, "")
            }
            r = e._expandFormat(r);
            for (var i = e._parseDateFormat(r), o = "", s = 0; s < i.length; s++)
                o += e._formatDatePart(n, r, i[s]);
            return o
        }

I wonder if it's possible to add a way to format the date with a specific UTC format... maybe an e._formatUTCDatePart? You have to use different functions for that because getting the date out in UTC format for Date objects requires you use functions like date.getUTCDate(); for the parts.

There is a property called showDatesAsGmt. I thought changing it from false to true would fix things. However it seems that the outsystems impementation of the grid just ignores it completely. So added some custom javascript as a work around. You have to clone and customize the DataGrid component to do this. In GridFramework javascript , add this


SyntaxEditor Code Snippet

                    if (_jsonData.length > 0) {
                        var fields = Object.getOwnPropertyNames(_jsonData[0]);
                        for (let row = 0; row < _jsonData.length; row++) {
                            for (let i = 0; i < fields.length; i++) {
                                var field = _jsonData[row][fields[i]];
                                if (field instanceof Date)
                                    _jsonData[row][fields[i]] = new Date(field.getTime() + field.getTimezoneOffset() * 60000); // 60000 = ms/min
                            }
                        }
                    }


It basically removes the time offset that was applied to your data. Add it right after this existing line of js.

SyntaxEditor Code Snippet

                    _jsonData = GridOS.ComponentUtils.getDataFromRest(_jsonData);

Hope that helps someone else. I can't figure out why there are not more people having this issue. My only guess is that most outsystems customers are in europe. Anyone in North America would be getting a time offset that would change the date and make it offset by 1 day. Hopefully outsystems will implement a more permanent fix that is accessible by a property.

Mark Jurkovich wrote:

There is a property called showDatesAsGmt. I thought changing it from false to true would fix things. However it seems that the outsystems impementation of the grid just ignores it completely. So added some custom javascript as a work around. You have to clone and customize the DataGrid component to do this. In GridFramework javascript , add this


SyntaxEditor Code Snippet

                    if (_jsonData.length > 0) {
                        var fields = Object.getOwnPropertyNames(_jsonData[0]);
                        for (let row = 0; row < _jsonData.length; row++) {
                            for (let i = 0; i < fields.length; i++) {
                                var field = _jsonData[row][fields[i]];
                                if (field instanceof Date)
                                    _jsonData[row][fields[i]] = new Date(field.getTime() + field.getTimezoneOffset() * 60000); // 60000 = ms/min
                            }
                        }
                    }


It basically removes the time offset that was applied to your data. Add it right after this existing line of js.

SyntaxEditor Code Snippet

                    _jsonData = GridOS.ComponentUtils.getDataFromRest(_jsonData);

Hope that helps someone else. I can't figure out why there are not more people having this issue. My only guess is that most outsystems customers are in europe. Anyone in North America would be getting a time offset that would change the date and make it offset by 1 day. Hopefully outsystems will implement a more permanent fix that is accessible by a property.

Thank you for the suggestions Mark. I will try and get back. 


Thanks and Regards,

Priya