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'
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);
}
Most helpful comment
got the solution form another issue.