datetime - conditional datetime formatting using the plugin functionality
datetime - conditional datetime formatting using the plugin functionality
Is there a way to do conditional datetime formatting using the plugin functionality?
The following works fine, so I know my 'from' format specifier is correct, except the null date values are transformed as "Invalid date":
{ "data": "UserDate", "render": $.fn.dataTable.render.moment( 'YYYY-MM-DDT00:00:00', 'YYYY-MM-DD' ) }
To try and amend it to account for null dates, I have tried this:
{ "data": "UserDate", "render": function ( data, type, full, meta ) {
return (data === null) ? data : $.fn.dataTable.render.moment( 'YYYY-MM-DDT00:00:00', 'YYYY-MM-DD' );}
},
Now the null values are fine, but I get "Invalid date" for the else portion of the conditional.
What syntax should I be using?
Thank you
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Try:
I haven't actually tried it, but I think that should work - although I haven't actually tested it.
Having said that, I think a better option would be to simply modify the plug-in to support
null
values. Pull requests for that improvement welcome ;-).Allan