EasyUI Forum
April 27, 2024, 05:41:01 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datagrid - formatting date dd/mm/yyyy (Solved)  (Read 15039 times)
peter900
Newbie
*
Posts: 22


View Profile Email
« on: April 12, 2016, 10:55:19 AM »

I don't understand why this code fails...

<th field="servicedate" formatter:function(value){
         var d = new Date(value);
         
         var y = d.getFullYear();
         var m = d.getMonth()+1;
         var d = d.getDate();
         return d+'/'+m+'/'+y;
         }         
          width="50">Service Date</th>

Hopefully someone can point out what I'm doing wrong.

Thanks.


« Last Edit: April 21, 2016, 02:57:05 AM by peter900 » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: April 14, 2016, 08:18:55 AM »

Please look at this example http://jeasyui.com/demo/main/?plugin=DataGrid&theme=default&dir=ltr&pitem=Format%20DataGrid%20Columns
Logged
peter900
Newbie
*
Posts: 22


View Profile Email
« Reply #2 on: April 14, 2016, 09:58:30 AM »

Thanks for this.

I modified the example, added a date column and changed the json to include  YYYY/mm/dd values...

Code:
<th data-options="field:'date1',width:100,align:'center',formatter:formatDate1">Date</th>

Code:
		
function formatDate1(val,row){
return formattedDate(val);
}

function formattedDate(date) {
var d = new Date(date || Date.now()),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();

if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;

return [day, month, year].join('/');
}

This code displays the dates as dd/mm/yyyy.

Perfect !  Thanks.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!