使用Laravel在数据表中添加删除按钮

时间:2016-10-20 06:59:15

标签: laravel datatables

我想在数据表列中添加删除按钮,但它不起作用。但我的编辑按钮工作完美。在这里,我发布了我的 Qus LINK  编辑按钮工作正常,但只有delet按钮错误

public function getRowDetailsData(PslCall $call)
    {
        $crews = Crew::Where('call_id',$call->id)->get();
        return Datatables::of($crews)
            ->addColumn('action', function ($crew) {
                return '<a href="crews/'.$crew->id.'/edit" class="btn btn-xs"><span class="glyphicon glyphicon-edit" data-toggle="tooltip" title="Edit"aria-hidden="true"></span></a>
                <form action="{{ route(\'crews.destroy\', $crew->id)}}" method="POST"><input type="hidden" name="_method" value="DELETE">
                <button type="submit" class="btn-xs  form-btn confirmation-callback" data-placement="left"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
                </form>';
            })
            ->editColumn('id', 'ID: {{$id}}')
            ->removeColumn('id')
            ->editColumn('arrival_date', function ($crew) {
                return $crew->arrival_date ? with(new Carbon($crew->arrival_date))->format('d-M-Y h:i') : '';
            })
            ->filterColumn('arrival_date', function ($query, $keyword) {
                $query->whereRaw("DATE_FORMAT(created_at,'%m/%d/%Y') like ?", ["%$keyword%"]);
            })->make(true);
    }

我的表就像这样

<table class="table table-striped table-bordered table-hover datas" cellspacing="0" width="100%">
                                    <thead>
                                    <tr>
                                        <th></th>
                                        <th>NAME</th>
                                        <th>GENDER</th>
                                        <th>TYPE</th>
                                        <th>ARRIVAL /DEPARTURE</th>
                                        <th>ACTION</th>
                                    </tr>
                                    </thead>
                                </table>

再次像我这样的剧本

var table = $('.datas').DataTable({
        processing: true,
        serverSide: true,
        ajax: '{{ url('calls/'.$call->id.'/row-details-data') }}',

        columns: [
            {
                "className":      'details-control',
                "orderable":      false,
                "searchable":     false,
                "data":           null,
                "defaultContent": '<span class="btn  btn-xs glyphicon glyphicon-download"></span>'
            },
            {data: 'crew_name', name: 'crew_name'},
            {data: 'gender', name: 'gender'},
            {data: 'crew_type'},
            {data: 'arrival_date', "render":function(data, type, row){
                switch(row.crew_type) {
                    case 'ONSIGNER' : return 'Arrival : '+ row.arrival_date; break;
                    case 'OFFSIGNER' : return 'Depart : '+ row.arrival_date; break;
                    default  : return 'N/A';
                }

            }},
            {data: 'action', name: 'action', orderable: false, searchable: false}
        ],

    } );

1 个答案:

答案 0 :(得分:0)

{!! Form::open(array('url' => '/crews/'.$crew->id, 'method' => 'delete')) !!}
<button type="submit" class="btn-xs  form-btn confirmation-callback" data-placement="left"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
!! Form::close() !!}