formatting date angularjs ui-grid
Asked Answered
R

3

21

I am trying to change the way date is being displayed. the data is coming as string with the format "Sun May 03 18:04:41 2009"

i looked at the examples, and they were asking me to use

$scope.gridOptions = {
  data: 'mydata',
  enableRowSelection: true,
  multiSelect: false,
  enableColumnResize: true,
  columnDefs: [
    { field: 'startDate', displayName: 'Date', cellFilter: 'date:\'yyyy-MM-dd\'' }]
};

however this is not working for me. Data is still being displayed as it is. Rather than "2009-05-13" Anything i am doing wrong? Thanks in advance!

Redeeming answered 10/8, 2015 at 21:7 Comment(2)
give a try by this cellFilter: 'date:"yyyy-MM-dd\"'Graphomotor
thanks for the help, but still not doing the trickRedeeming
O
11

It looks like you are trying to use an incompatible date format with the Angular date filter. The docs say that it needs to be a Date object, milliseconds or an ISO 8601 date. Since your date string doesn't match any of that you will either need to roll your own string formatter or convert that value to a Date object or milliseconds before passing it to the date filter.

Onder answered 10/8, 2015 at 21:57 Comment(0)
O
50

Use: type: 'date', cellFilter: 'date:\'MM/dd/yyyy\''

$scope.gridOptions = {
data: 'mydata',
enableRowSelection: true,
multiSelect: false,
enableColumnResize: true,
columnDefs: [
{ field: 'startDate', displayName: 'Date',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }]};
Olva answered 13/8, 2015 at 23:17 Comment(3)
can we add custom filter function in cellFilter?Ganger
@AnitaMehta yes you can add custom cell filter functionPipkin
type date shows a datepicker in edit mode. but value is not binding instead it shows placeholder mm/dd/yyyyMestizo
O
11

It looks like you are trying to use an incompatible date format with the Angular date filter. The docs say that it needs to be a Date object, milliseconds or an ISO 8601 date. Since your date string doesn't match any of that you will either need to roll your own string formatter or convert that value to a Date object or milliseconds before passing it to the date filter.

Onder answered 10/8, 2015 at 21:57 Comment(0)
M
2

Use cellFilter: 'date:"longDate"'

columnDefs: [
         { name: "ID", displayName: "ID"},
         { name: "Date", displayName: "Date", cellFilter: 'date:"longDate"'},
Morelock answered 1/5, 2016 at 14:11 Comment(1)
this is the format now it seems cellFilter: 'date:longdate'Photogene

© 2022 - 2024 — McMap. All rights reserved.