Reputation: 375
I want to display from my database a timestamp data type in ajax datatable.
But when the data table loads it shows "[object Object]" instead of a datetime format.
Could there be anything I need to add?
Here is my ajax code:
function search() {
$('#data-table').DataTable({
"processing": true,
"serverSide": true,
"ajax":{
"url": "{{ route('cust_continfo_data_table') }}",
"dataType": "json",
"type": "POST",
"data":{ _token: "{{ csrf_token() }}" }
},
"columnDefs": [
{ "white-space": 'nowrap', "targets": 4 },
{ "overflow": 'hidden', "targets": 4 },
{ "max-width": '150px', "targets": 4 },
],
"columns": [
{ "data": "id" },
{ "data": "receipt_date" },
{ "data": "info_division_name" },
{ "data": "contact_status" },
{ "data": "note" },
{ "data": "created_at" },
{ "data": "updated_at" }
],
"pageLength": 10,
"searching": false,
"info": false,
"lengthChange": false,
"oLanguage": {
"oPaginate": {
"sPrevious": "{{ trans('pagination.previous') }}",
"sNext": "{{ trans('pagination.next') }}",
},
"sEmptyTable": "{{ trans('data-table.empty_table') }}",
"sProcessing": "{{ trans('data-table.processing') }}",
},
});
}
created_at
and updated_at
are the timestamp data type that shows [object Object].
How can make it in datetime format?
Upvotes: 0
Views: 788
Reputation: 304
You can create a valid format on controller side, where you are creating created_at and updated_at value, like this:-
$createdAt = 2018-01-23;
'created_at' => date('Y-m-d', strtotime($createdAt))
Upvotes: 1