属性标记在前端不起作用

时间:2019-01-07 04:10:43

标签: laravel datatable

我正在尝试将属性标签从控制器返回到前端,但是属性链接和类无法正常工作。

Click here (image)

控制器端

public function religionlist(){

    $view_data = DB::select("SELECT 
                                id,religion
                            FROM 
                                hrm_religion");


    $religion_data   = collect($view_data);

    return DataTables::of($religion_data)
    ->addColumn('Link', function ($religion_data) {
       return 
       ' <a href="'. url('/religion') . '/' . 
       Crypt::encrypt($religion_data->id) . 
       '/edit' .'"' . 
       'class="btn btn-success btn-sm block btn-flat"><i class="glyphicon glyphicon-edit-sign" id="customer-confrimed"></i> confirm</a>';        
     })
    ->editColumn('id', '{{$id}}')
    ->setRowId('id')
    ->make(true);


}

前端面

$(document).ready(function() {
  var table = $('#list_table').DataTable( {
    "processing": true,
    "serverSide": true,
    "paging": true,
    "ajax": "{{URL::to('/')}}/religion_list",
    "columns": [
        { "data": "religion" },
        { "data": "Link", name: 'action', orderable: false, searchable: false},
    ],
    "order": [[0, 'asc']]
  });

});

1 个答案:

答案 0 :(得分:1)

您可以用下面的一个替换您的return语句吗?

return '<a href="'.url('religion').'/'.Crypt::encrypt($religion_data->id).'/edit" class="btn btn-success btn-sm block btn-flat"><i class="glyphicon glyphicon-edit-sign" id="customer-confrimed"></i> Confirm</a>'

请在下面的链接中查看此内容

https://github.com/yajra/laravel-datatables/issues/1305

只需在代码中添加->rawColumns(['Link'])

 return DataTables::of($religion_data)
    ->addColumn('Link', function ($religion_data) {
       return 
       ' <a href="'. url('/religion') . '/' . 
       Crypt::encrypt($religion_data->id) . 
       '/edit' .'"' . 
       'class="btn btn-success btn-sm block btn-flat"><i class="glyphicon glyphicon-edit-sign" id="customer-confrimed"></i> confirm</a>';        
     })
    ->editColumn('id', '{{$id}}')
    ->setRowId('id')
    ->rawColumns(['Link'])
    ->make(true);