Edit Date Format
Edit Date Format
So I am attemting to edit a date that is displayed yyyy/mm/dd hh:mm:ss into dd/mm/yyyy.
I believe I installed moment.js and added to my scrip before datatables. Then for render I have this.
I don't get any error, but the date stays in the same format. I have looked through a few examples and tried them, but none seem to work.
{ "data": "OrderDtl_NeedByDate",render : $.fn.dataTable.moment('DD/MM/YYYY')},
<script type='text/javascript'>
var resData = <%-(data)%>;
$(document).ready(function(){
$('#OpenOrders').DataTable( {
dom: 'Blfrtip',
lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
buttons: [{extend: 'excel' , className: 'badge badge-info'},
{extend: 'pdf' , className: 'badge badge-info'},
],
"data": resData.value,
"columns": [
{ "data": "OrderHed_OrderNum", },
{ "data": "OrderDtl_OrderLine" },
{ "data": "OrderHed_PONum" },
{ "data": "OrderDtl_XPartNum" },
{ "data": "OrderDtl_length_c",},
{ "data": "OrderDtl_Pieces_c", },
{ "data": "OrderDtl_OrderQty",render: $.fn.dataTable.render.number( ',', '.', 2, '' )},
{ "data": "Calculated_ShipPCS",render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
{ "data": "Calculated_AvailablePCS",render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
{ "data": "Calculated_ReadyPCS",render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
{ "data": "OrderDtl_DocUnitPrice" },
{ "data": "OrderDtl_NeedByDate",render : $.fn.dataTable.moment('DD/MM/YYYY')},
]
});
})
</script>
This question has an accepted answers - jump to answer
Answers
When you say edit, are you using Editor or some other approach? I'm not seeing Editor in your code samples?
Colin
In line 27 you are trying to use this to format the date.
$.fn.dataTable.moment('DD/MM/YYYY')}
is used to define the datetime format used for sorting when using the plugin described in this blog. You will want to use the moment.js library for this. Something like this:Here is another recent thread discussing a similar question.
Kevin
This did it.
{ "data": "OrderDtl_NeedByDate",},