formatting date angularjs ui-grid

myTD picture myTD · Aug 10, 2015 · Viewed 37.8k times · Source

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!

Answer

vvardhanz picture vvardhanz · Aug 14, 2015

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\'' }]};