Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

formatting date angularjs ui-grid

Tags:

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!

like image 773
myTD Avatar asked Aug 10 '15 21:08

myTD


2 Answers

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\'' }]}; 
like image 120
vvardhanz Avatar answered Sep 21 '22 17:09

vvardhanz


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.

like image 22
Matthew Green Avatar answered Sep 19 '22 17:09

Matthew Green