Solved

Angular ui-grid Date format

Posted on 2016-10-02
7
108 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTP Load with Angular.js 6 101
To learn Core 1.0 or Angular? 3 65
How to Chain multiple custom filters with AngualrJS 3 45
Angular.js example vocabulary extensions 5 50
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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now