Laravel-datatables: Datatables as Service add columns to Show,Edit and Delete

Created on 20 Mar 2016  ·  3Comments  ·  Source: yajra/laravel-datatables

Summary of problem or feature request

I am planning to use Datatables as Service and i need to add Show,Edit and Delete columns. I found an example in the documentation (http://datatables.yajrabox.com/eloquent/add-edit-remove-column) but could not find any for 'Datatables as Service'

System details

  • Laravel Version : 5.1
  • Laravel-Datatables Version : "yajra/laravel-datatables-oracle": "~6.0"

Most helpful comment

got the solution form another issue.

public function ajax() {
        $query = $this->query();

        return $this->datatables
                        ->eloquent($this->query())
                        ->addColumn('action', function ($query) {
                            return '<a href="' . route("admin.districts.edit", $query->id) . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
                        })
                        ->make(true);
    }

All 3 comments

got the solution form another issue.

public function ajax() {
        $query = $this->query();

        return $this->datatables
                        ->eloquent($this->query())
                        ->addColumn('action', function ($query) {
                            return '<a href="' . route("admin.districts.edit", $query->id) . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
                        })
                        ->make(true);
    }

Hello Yajra, I need to add delete and edit button with different column but i am using action it only use one column. show what i do?? can you help me

got the solution form another issue.

public function ajax() {
        $query = $this->query();

        return $this->datatables
                        ->eloquent($this->query())
                        ->addColumn('action', function ($query) {
                            return '<a href="' . route("admin.districts.edit", $query->id) . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
                        })
                        ->make(true);
    }

For anyone who gets the raw HTML printed out when doing this, I also had to add rawColumns('action') to prevent the HTML getting escaped, i.e:

public function ajax() {
        $query = $this->query();

        return $this->datatables
                        ->eloquent($this->query())
                        ->addColumn('action', function ($query) {
                            return '<a href="' . route("admin.districts.edit", $query->id) . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
                        })
                        ->rawColumns(['action'])
                        ->make(true);
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  ·  3Comments

kamrava picture kamrava  ·  3Comments

shadoWalker89 picture shadoWalker89  ·  3Comments

t0n1zz picture t0n1zz  ·  3Comments

jgatringer picture jgatringer  ·  3Comments