var table = $('#customer-table').DataTable({
processing: true,
serverSide: true,
ajax: "{{ route('api.users') }}",
columns: [
{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'title', name: 'title'},
{data: 'date', name: 'date'},
]
});
</script>
`Route::get('/apiUsers','UserController@apiUsers')->name('api.users');`
public function apiUsers()
{
$customer = Customer::all();
return Datatables::of($customer)
->addColumn('action', function($customer){
return'<a onclick="editForm('. $customer->id .')" class="btn btn-primary btn-xs"><i class="glyphicon glyphicon-edit"></i> Edit </a> ' .
'<a onclick="deleteData('. $customer->id .')" class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"></i> Delete </a>';
})
->rawColumns(['action'])->make(true);
}
<script src=" {{ asset('assets/bower_components/datatables.net/js/jquery.dataTables.min.js') }} "></script>
<script src="{{ asset('assets/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js') }} "></script>
以上是代码。我可以知道如何只显示匹配结果而不是首先显示整个数据库然后只显示搜索结果吗?我也包含了使用的数据表脚本。谢谢!