Laravel Server Side Datatables
Install ini
composer require yajra/laravel-datatables-oracle:"~9.0"
Buat Ajax Pada Controller
public function ajax()
{
// echo "ok";
$db = fnosql("guru");
$data = $db->findAll();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function ($row) {
$actionBtn = '<a href="' . url('/guru/edit') . '/' . Crypt::encrypt($row["_id"]) . '" class="edit btn btn-success btn-sm">Edit</a> <a href="' . url('/guru/hapus') . '/' . Crypt::encrypt($row["_id"]) . '" class="delete btn btn-danger btn-sm">Delete</a>';
return $actionBtn;
})
->rawColumns(['action'])
->make(true);
// return datatables($data)->toJson();
}
Buat Blade , Contoh
<table class="table table-bordered user_datatable">
<thead>
<tr>
<th>nama</th>
<th>umur</th>
<th>mata_pelajaran</th>
<th>action</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</body>
<script type="text/javascript">
$(function() {
var table = $('.user_datatable').DataTable({
processing: true,
serverSide: true,
ajax: "{{ url('guru/ajax') }}",
columns: [{
data: 'nama',
name: 'nama'
},
{
data: 'Umur',
name: 'Umur'
},
{
data: 'mata_pelajaran',
name: 'mata_pelajaran'
},
{
data: 'action',
name: 'action',
orderable: true,
searchable: true
},
]
});
});
</script>
Lanjut Part : 1
Muhammad Ullil Fahri
WA : 089696380422
Tautan WA : https://wa.me/message/SG4YA2XQP5FPE1