0

我需要在我的数据表列中格式化日期,我正在阅读文档,但我不知道该怎么做。

我有这个代码来创建我的数据表:

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 --}}

并在我的控制器中返回 Datatable 实例:

$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);

但我不知道如何格式化这个日期。

感谢帮助。

4

2 回答 2

0

您可以使用数据表中的 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);
            },
于 2021-07-09T08:51:27.810 回答
0

我用以下方法解决我的问题:

{ data: 'fechaAsignacion', render: function (data, type, row) {
                return moment(new Date(data).toString()).format('DD/MM/YYYY HH:mm:ss');
                } 
            },

在我的专栏中date使用我的格式创建格式我必须包含矩库 jquery

于 2021-07-10T15:02:41.293 回答