dimanche 27 septembre 2020

How to add action columns in yajra datatables laravel

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">
                            
                        </div>
                    @endif
                </div>
            <div class="card-body">
              <div class="table-responsive">
                <div class="panel panel-default">
                
              </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



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3kVvLbA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire