【问题标题】:Add delete button in Data table with Laravel使用 Laravel 在数据表中添加删除按钮
【发布时间】:2016-10-20 06:59:15
【问题描述】:

我试图在数据表列中添加删除按钮,但它不起作用。但我的编辑按钮效果很好。我在这里发布了我的 QusLINK 编辑按钮完美,但删除按钮只有错误

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

    } );

【问题讨论】:

    标签: laravel datatables


    【解决方案1】:

    五月

    {!! 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() !!}
    

    【讨论】:

    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 2019-02-21
    • 2018-10-14
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    相关资源
    最近更新 更多