I'm using datatables.net jquery plugin and populating the data through asp.net mvc4.
One of my columns is a date format. I'm interested in changing the format of how it is displayed but not changing the type of the column from date to string.
I'm currently using default initialization:
$('#data-table').dataTable();
My 4th column is a date "Created Date" and is currently displayed as "7/07/2013 9:38:11 p.m." I would like it to be displayed as either "7/07/2013" or "7 Jul 2013".
I thought this was a relatively easy task but haven't been able to find the answer I'm after.
I'd like to avoid additional plugins if possible. Is there a simple way that I'm missing?
Here is what I came up with. Using how it renders I can manipulate the way the date is displayed to anyway I want.
$('#data-table').dataTable({
"aoColumnDefs": [
{
"aTargets": [0],
"bSearchable": false,
"sType": 'date',
"fnRender": function ( oObj ) {
var javascriptDate = new Date(oObj.aData[0]);
javascriptDate = javascriptDate.getDate()+"/"+(javascriptDate.getMonth()+1)+"/"+javascriptDate.getFullYear();
return "<div class='date'>"+javascriptDate+"<div>";
}
}
]
});
I hope this will be useful to others...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With