如何解决格式化数据表中的日期列
我需要在我的数据表列中格式化日期,我正在阅读文档,但我不知道该怎么做。
var callTable = $('#calls').DataTable({
dom: 'Bfrtip',language: {
url: "{{ asset('js/plugins/datatables/spanish.json') }}",},buttons: [
'pdf'
],processing: true,serverSide: true,ajax: "{{ route('jefasala.listado.getCall') }}",columnDefs: [{
'targets': 0,'searchable': false,'orderable': false,'className': 'dt-body-center','render': function (data,type,full,Meta){
return '<input type="checkBox" class="checkBoxes" name="id[]" value="' + $('<div/>').text(data).html() + '">';
},}],select: {
style: 'os',selector: 'td:first-child'
},// if datatable it´s correct created
"drawCallback": function( settings ) {
fillSelectOperator();
// this change operator for call
$(".select_operator").on("change",function(e){
let callId = $(e.target).closest('tr').find("td:eq(1)").html();
let operatorId = $(this).val();
let token = $('Meta[name=csrf-token]').attr('content');
var modalConfirm = function(callback){
$("#modalConfirm").modal('show');
$("#confirmOperator").on("click",function(){
$.ajax({
url: "{{ route('jefasala.listado.llamadas.asignar') }}",type: "POST",data: { "callId": callId,"operatorId": operatorId,"_token":token },success: function(response){
$("#assignOk").show();
$("#assignOk").append(response);
location.reload();
},error: function(xhr){
$("#errorAssign").show();
$("#errorAssign").append(xhr.responseText);
}
});
$("#modalConfirm").modal('hide');
});
$("#cancelOperator").on("click",function(){
callback(false);
$("#modalConfirm").modal('hide');
});
};
modalConfirm(function(confirm){
if(confirm){
console.log("eee");
}else{
//Acciones si el usuario no confirma
$("#result").html("NO CONFIRMADO");
}
});
});
填充它的所有数据,它在数据库中,我正在使用后端 laravel 5.6
和数据表 yajra
。
我的桌子是:
<table id="calls" class="table table-hover table-condensed display mb-5" style="width:100%">
<thead class="thead-dark">
<tr>
<th>
<input style="style=border: none; background: transparent; font-size: 14px;" type='checkBox' id='checkall' class="checkall">
</th>
<th>Id</th>
<th>Nombre</th>
<th>Direccion</th>
<th>Provincia</th>
<th>Ciudad</th>
<th>Teleoperador/a</th>
<th>Reasignar</th>
<th>Est.Llamada</th>
<th>Est.Cita</th>
<th>F.Asignacion</th>
<th>Acciones</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Direccion</th>
<th>Direccion</th>
<th>Provincia</th>
<th>Ciudad</th>
<th>Teleoperador/a</th>
<th>Reasignar</th>
<th>Estado Llamada</th>
<th>Estado Cita</th>
<th>Fecha Asignacion</th>
</tr>
</tfoot>
</table>{{-- TABLE CALL --}}
并在我的控制器中返回数据表的实例:
$llamadas = DB::table('users')->join('llamada','users.id','=','llamada.id_teleoperadora')
->join('llamada_estado','llamada_estado.id','llamada.id_estado')
->join('cita','llamada.id','cita.id_llamada')
->join('cita_estado','cita.id_estado','cita_estado.id')
->select(
'llamada.id AS identi','llamada.nomape as nombre','llamada.ciudad as ciudad','llamada.provincia as provincia','llamada.direccion as direccion','llamada.cp as cp','llamada.telefono as telefono','users.nombre AS teleoperadora','llamada_estado.nombre AS estado','cita_estado.nombre as estadoCita','llamada.fecha_asignacion as fechaAsignacion','llamada.updated_at as updated'
)
->get();
return Datatables::of($llamadas)
->addColumn('action',function(){
$btn = '<a href="#" data-toggle="modal" data-target="#modalCall" class="editCall btn btn-primary btn-sm">
<i class="fas fa-eye"></i>
</a>';
return $btn;
})
->rawColumns(['action'])
->make(true);
但我不知道如何格式化这个日期。
感谢您的帮助。
解决方法
您可以使用数据表中的 createRow 回调
fnCreatedRow : function (nRow,aData,iDataIndex)
{
let date = (aData[1]); // assume date is in column 1
// format date here
$('td:eq(1)',nRow).html(date);
},
,
我通过以下方式解决了我的问题:
{ data: 'fechaAsignacion',render: function (data,type,row) {
return moment(new Date(data).toString()).format('DD/MM/YYYY HH:mm:ss');
}
},
在我的带有 date
的专栏中,使用 moment 以我的格式创建格式,我必须包含 moment 库 jquery
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。