abu abu
abu abu

Reputation: 7042

Output of Laravel datatable

I am using Laravel 5.4 and Datatable 7.x. I am using AdminLTE also. I need a column named 'Status'. I wrote below code in controller.

return Datatables::of($users)
            ->addColumn('status', function(Users $users){
                $status     =   (($users->status == 1)?
                                    '<a href="" class="btn btn-xs btn-warning"><i class="fa fa-eye"></i></a>'
                                    :
                                    '<a href="" class="btn btn-xs btn-warning"><i class="fa fa-eye-slash"></i></a>'
                                );

                $html       =   '<div class="btn-group">
                                    '.$status.'
                                </div>';

                return $html;
            })
            ->setRowId('id')
            ->make(true);

My output is like below

enter image description here

But I need the button. Can anyone help me in this regard ?

Upvotes: 0

Views: 223

Answers (1)

Dan Mason
Dan Mason

Reputation: 2337

If you want to use html or views in the setColumn method then you need to declare the columns in the rawColumns method so that it doesn't escape the HTML.

 return Datatables::of($users)
            ->addColumn('status', function(Users $users){
                $status     =   (($users->status == 1)?
                                    '<a href="" class="btn btn-xs btn-warning"><i class="fa fa-eye"></i></a>'
                                    :
                                    '<a href="" class="btn btn-xs btn-warning"><i class="fa fa-eye-slash"></i></a>'
                                );

                $html       =   '<div class="btn-group">
                                    '.$status.'
                                </div>';

                return $html;
            })
            ->setRowId('id')
            ->rawColumns(['status'])
            ->make(true);

https://yajrabox.com/docs/laravel-datatables/master/raw-columns

Upvotes: 1

Related Questions