this my controller
if ($request->ajax())
{
$fields = Field::select(['id_lapangan','nama_lapangan','harga_sewa','gambar']);
return Datatables::of($fields)
// ->addColumn('action', function($field){
// return view('datatable._action', [
// 'model' =>$field,
// 'form_url'=>route('field.destroy', $field->id),
// 'edit_url'=>route('field.edit',$field->id),
// 'confirm_message'=>'yakin mau hapus'.$field->name .'?'
// ]);
// })
->make(true);
}
$html = $htmlBuilder
->addColumn(['data'=>'id_lapangan','name'=>'id_lapangan','title'=>'No.'])
->addColumn(['data'=>'nama_lapangan','name'=>'nama_lapangan','title'=>'Nama Lapangan'])
->addColumn(['data'=>'harga_sewa','name'=>'harga_sewa','title'=>'Harga Sewa'])
->addColumn(['data'=>'gambar','name'=>'gambar','title'=>'Gambar'])
->addColumn(['data'=> 'action' , 'name' => 'action' , 'title' => '' ,
'orderable' =>false , 'searchable' => false ]);
return view('fields.index')->with(compact('html'));
this my index.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
<ul class="breadcrumb">
<li><a href="{{ url('/home') }}">Dashboard</a></li>
<li class="active">Jadwal</li>
</ul>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Lapangan</h2>
</div>
<div class="panel-body">
{!! $html->table(['class'=>'table-striped table-bordered']) !!}
</div>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
{!! $html->scripts() !!}
@endsection
When I run on my browser, the data in the database does not appear, and the eror is TypeError: f is undefined
I would imagine it's because you've got 5 columns in your setup but for your ajax call you're only returning 4.
Either comment out:
->addColumn(['data'=> 'action' , 'name' => 'action' , 'title' => '' , 'orderable' =>false , 'searchable' => false ]);
Or add the logic back in for the ajax section.
Hope this helps!