ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

CellFilter Date Format

Open redapplewithleaves opened this issue 11 years ago • 8 comments

How do I form the date time with the cell filter? I found samples of date only, but I need a bit of help formatting it.

http://plnkr.co/edit/HiCt52ntdWDHtgXN8x0A?p=preview

"2015-02-03T05:49:54.850Z" to 2015-02-03 5:49 AM OR "2015-02-02T17:09:37.790Z" to 2015-02-02 17:09

  1. Date with filter converts the time automatically to GMT-0. Why?
  2. How do I format the cell filter so that it keeps it in the same timezone?
  3. Also, how about the AM and PM?

redapplewithleaves avatar Feb 04 '15 19:02 redapplewithleaves

The filter is the standard angularJS date filter, and behaves in the same way as that filter. I suspect the time format is driven by your browser. Refer https://docs.angularjs.org/api/ng/filter/date

PaulL1 avatar Feb 05 '15 03:02 PaulL1

Oh! Okay. Thanks for the link and quick response.

I had to use moment.timezone.js to get it to work :)

redapplewithleaves avatar Feb 05 '15 15:02 redapplewithleaves

@redapplewithleaves, how did you get this to work?

When using ng-grid I cannot override the system time zone with date:'2015-02-03T05:49:54.850Z':'-0600'

drewturk avatar Jun 10 '15 20:06 drewturk

I made helper functions that takes in the value using moment.js (http://momentjs.com/)

        function formatDateTime(value) {
            if (value) {
                var v = moment(value).format('YYYY-MM-DD');
                //default null value for my db
                if (v == "12-31-1899") {
                    return "";
                } else {
                    return v;
                }
            }
            return "";
      }

I called that function in a for-loop or set it up in model of the object. Then just used the return values to display it to the grid.

image

With moments.js its easier to override the timezone.

redapplewithleaves avatar Jun 10 '15 21:06 redapplewithleaves

thanks, I will try that.

So just to confirm, you did experience trouble with supplying a timezone when using cellFilter in colDefs or even date filter within a custom cellTemplate?

When I use either method, I can never override the timezone. Is this a known issue with ng-grid? For example: {{row.getProperty(col.field) | date:'yyyy-MM-dd HH:mm:ss Z':'-0800'}}, does not change the time zone to -0800, but would still use the system/browser timezone. Or am I using incorrect syntax?

Thanks.

drewturk avatar Jun 11 '15 19:06 drewturk

This is still a known issue. It would be possible to use moment as suggested earlier, but that solves the date format issue, which I don't seem to have a problem with if inserted this way:

{ displayName: 'Some Date', field: 'fieldfromdb', cellFilter: 'date : \'MM-DD-YYYY\'', }`

However, what seems like an easy implementation of timezone in the ui-grid's gridOptions object (in the same fieldfromdb object) doesn't seem to be working:

{ displayName: 'Some Date', field: 'fieldfromdb', cellFilter: 'date : \'MM-DD-YYYY\' : \'UTC\'', }

Any updates on this issue?

tramel-woodard avatar Aug 16 '17 08:08 tramel-woodard

I am having the same issue, I am able to resolve this issue in other ways like using JavaScript functions but I want to convert my date in CellFilter, not just UTC, it should pick the browser timezone. It will be helpful for short coding.

Thanks

asjadali0 avatar Sep 05 '17 07:09 asjadali0

But if the date value is unix seconds rather than milliseconds, how to fix this?

katherine-liu avatar Aug 01 '18 20:08 katherine-liu