Solved

Angular ui-grid Date format

Posted on 2016-10-02
7
343 Views
Last Modified: 2016-11-13
Hi, I am trying to format the Date column in angular ui-grid(version 3.2.8) But it is not working.
The Dates are passing to getCellFormatDate function as Ex: 2016-09-27 15:18:26 But it is returning 0(zero). Plz suggest how to return it as
yyyy-MM-dd  

Grid columns definition
$scope.gridOptions = {
data: 'mydata',
enableRowSelection: true,
multiSelect: false,
enableColumnResize: true,
columnDefs: [
{ field: 'startDate', displayName: 'Date',type: 'date', 
cellTemplate: <div>{{grid.appScope.getCellFormatDate(row.entity.startDt}}</div>}]};

Open in new window

JavaScript code
$scope.getCellFormatDate = function(dt)
{
$scope.dtFormated = dt |'date:\'yyyy-MM-dd\'';
return $scope.dtFormatted;
};

Open in new window

Thanks
0
Comment
Question by:KavyaVS
  • 3
  • 2
  • 2
7 Comments
 
LVL 28

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 150 total points
ID: 41825782
I think format is not correct or supported.

Could you please try

date:'yyyy-MM-dd'

Also try

'date:'yyyy-MM-dd''

Please let me know if you still face after these.
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41825783
Or may be full one

date:'yyyy-MM-dd HH:mm:ss Z'
0
 

Assisted Solution

by:KavyaVS
KavyaVS earned 0 total points
ID: 41826291
Hi,I tried 3 options provided. But none of them working. We need to escape the single quotes around the format and date should be in quotes otherwise it is showing the red squiggly line while coding itself. Thanks
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 27

Accepted Solution

by:
BigRat earned 350 total points
ID: 41827851
According to your column definitions the TYPE of the date column is "date", but you're probably passing a string.

I don't think that $scope.dtFormated = dt |'date:\'yyyy-MM-dd\''; does a pipe operation. I would personally prefer, if I was to use a function like this to use one of the Javascript Date.xxx methods to format the date in the way you want. I suspect that the dt parameter is of type string. This will particularly be the case if the data comes from a server via JSON since JSON does not have a Date type.
0
 

Author Comment

by:KavyaVS
ID: 41847575
Yes. The data coming from the server via json. I tried to convert string Date as Date type. But it couldn't .It was undefined. Any suggestions plz.

Thanks
0
 
LVL 27

Assisted Solution

by:BigRat
BigRat earned 350 total points
ID: 41848037
Could you please post the JSON which comes back from the server?
0
 

Author Closing Comment

by:KavyaVS
ID: 41885327
Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
You have this traditional web application that refreshes the whole page each time you navigate and you think it's a good time to convert it to a Single-Page approach. What should you know in advance? Read on, I'll guide you through it.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question