Solved

Angular ui-grid Date format

Posted on 2016-10-02
7
574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 29

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 29

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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

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.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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