I love datatables, it has made my project so much easier to develop.
I am getting my data from an Ajax call and one of those columns is a date which can have a null value. I want to format the date value to be the same as a toDateString call on a Javascript Date. How can I achieve this? I have tried the below.
The JSON response is this.
As you can see the first entry has no runDate value so it correctly uses the current date in the format I want, but the second entry has a date and I get the data presented to the UI exactly as you see it here.
I also have another table that has a date/time column which I would like formatted as 'DDD dd MM yyyy hh:mm:ss'
Any pointers will be very much appreciated.
Thanks
I am getting my data from an Ajax call and one of those columns is a date which can have a null value. I want to format the date value to be the same as a toDateString call on a Javascript Date. How can I achieve this? I have tried the below.
$('#scheduledata').dataTable({ "bProcessing": true, "bDestroy": true, "sAjaxDataProp": "triggerList" "sAjaxSource": "/freewheel/api/triggers/queued" "aoColumns": [ {"mData": "trigger.job.@uid"} {"mData": "trigger.job.@name"} {"mData": "trigger.runDate", "sDefaultContent": (new Date()).toDateString(), "dateFormat": "dd/MM/yyyy" } {"mData": "trigger.triggerTime"} {"mData": "trigger.job.executingServer.@name"} ] "aaSorting": [ [2, "asc"] [3, "asc"] ], "aoColumnDefs": [ { "bSearchable": false, "bVisible": false, "aTargets": [0]} ], "bJQueryUI": true })
The JSON response is this.
{ "triggerList": [ { "trigger": { "@type": "RepeatingTrigger", "@uid": "32768", "job": { "@name": "Test Job", "@stderr": "stderr.log", "@stdout": "stdout.log", "@type": "CommandJob", "@uid": "65536", "command": "java -version", "executingServer": { "@name": "localhost", "@port": "12145", "@uid": "1" }, "jobType": "COMMAND" }, "triggerInterval": "50000", "triggerTime": "23:01:07.174", "triggerType": "REPEATING" } }, { "trigger": { "@type": "TimedTrigger", "@uid": "32769", "daysOfWeek": [ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY" ], "job": { "@name": "Test Job2", "@stderr": "stderr.log", "@stdout": "stdout.log", "@type": "CommandJob", "@uid": "65537", "command": "java -version", "executingServer": { "@name": "localhost", "@port": "12145", "@uid": "1" }, "jobType": "COMMAND" }, "runDate": "2013-06-03+01:00", "triggerTime": " 1:07:37.772", "triggerType": "TIMED" } } ] }
As you can see the first entry has no runDate value so it correctly uses the current date in the format I want, but the second entry has a date and I get the data presented to the UI exactly as you see it here.
I also have another table that has a date/time column which I would like formatted as 'DDD dd MM yyyy hh:mm:ss'
Any pointers will be very much appreciated.
Thanks