return Invalid Date DataTable
return Invalid Date DataTable
Unfazed_
Posts: 2Questions: 1Answers: 0
Hello Guys, what´s Up ?
Function
$.fn.dataTable.render.moment('YYYY-MM-DD HH:mm:ss', 'DD/MM/YYYY HH:mm:ss');
I have a problem getting the function above. The dataTable return me invalid Date when i use the following code:
{
data: 'end_campaign',
className: 'text-nowrap',
render: function (data) {
if(data != 'In progress'){
return $.fn.dataTable.render.moment('YYYY-MM-DD HH:mm:ss', 'DD/MM/YYYY HH:mm:ss');
}else{
return data
}
}
}
I'm recieve this in back-end:
'end_campaign' => ($campaignEnd->format("Y-m-d H:i:s") != $campaignStart->format("Y-m-d H:i:s")) ? $campaignEnd->format("Y-m-d H:i:s") : 'In progress',
Somebody can help me ?
This discussion has been closed.
Answers
Can you provide a simple example so we can see the actual date format returned from the server? I'm not sure what
$campaignEnd->format("Y-m-d H:i:s")
will return.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@kthorngren
This return is comming from laravel, i can show this case in the example ????
(sorry i´m noob in dataTables)
While setting up an example for you to start from I found the problem. You are using
return $.fn.dataTable.render.moment(...)
inside a render function. Thedata
assigned to the column doesn't get sent as a parameter to the plugin function. It is meant to be used like thisrender: $.fn.dataTable.render.moment(...)
as shown in the plugin docs and the renderer docs.Since you want to use a render function with an if statement then you will need to use the
moment()
function directly. Here is an example with your render function:http://live.datatables.net/bawukoke/1/edit
Also this shows how you can provide us with test cases using your data
Kevin