im stuck adding column actions for edit and delete button with yajra datatables, im using DataTables Service because im wanna add export button too, here is my my datatables code :
public function dataTable($query)
{
return datatables()
->eloquent($query);
}
/**
* Get query source of dataTable.
*
* @param \App\InfoDataTable $model
* @return \Illuminate\Database\Eloquent\Builder
*/
public function query(InfoDataTable $model)
{
// return $model->newQuery();
$data = DataInfo::select('data-info.*');
return $this->applyScopes($data);
}
/**
* Optional method if you want to use html builder.
*
* @return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->columns($this->getColumns())
->addAction()
->parameters([
'dom' => 'Bfrtip',
'buttons' => ['csv', 'excel', 'print'],
]);
}
/**
* Get columns.
*
* @return array
*/
protected function getColumns()
{
return [
Column::make('employee_no'),
Column::make('name'),
Column::make('address'),
Column::make('birthplace'),
Column::make('birthdate'),
Column::make('age'),
Column::make('occupation'),
Column::make('status'),
Column::make('gender'),
Column::make('startdate'),
];
}
and here is my code in my controller for rendering the table
public function index(InfoDataTable $dataTable)
{
$User = User::where('id', Auth::id())->first();
if($User->role == 'superadmin'){
return $dataTable->render('superadmin.index');
} else {
return $dataTable->render('admin.index');
}
}
and my blade looks like this
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
</div>
<div class="card-body">
<div class="table-responsive">
<div class="panel panel-default">
{{(!! $dataTable->table() !!)}}
</div>
</div>
</div>
</div>
</div>
</div>
@stop
@push('scripts')
{!! $dataTable->scripts() !!}
@endpush
my current view looks like this
any suggestions? sorry for my broken english, tried many tutorial but can't find the correct one
Actions column is default for yajra datatables. So I found how to remove it: https://yajrabox.com/docs/laravel-datatables/6.0/remove-column (I have never tried this)
If you want to edit actions column, try my code:
This is what in datatables_actions (full name: datatables_actions.blade.php)
My code is different from yours, so I will show my code:
Datatables code:
Controller code:
Blade code:
datatables_actions blade code:
Put file datatables_actions here: datatables_actions:
Code maybe have differences because of Boostrap, jQuery,... version