EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: peter900 on April 12, 2016, 10:55:19 AM



Title: Datagrid - formatting date dd/mm/yyyy (Solved)
Post by: peter900 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.




Title: Re: Datagrid - formatting date dd/mm/yyyy
Post by: jarry 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


Title: Re: Datagrid - formatting date dd/mm/yyyy
Post by: peter900 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.