laravel-datatables
laravel-datatables copied to clipboard
Only show table header (without content) using Html builder via method injection
I use this method and only show header table without its contents.
But, when I change to this.
if (true) { //change $request->ajax() with true
$authors = Author::select(['id', 'name']);
return Datatables::of($authors)->make(true);
}
It can show the content like this:
{"draw":0,"recordsTotal":17,"recordsFiltered":17,"data":[{"id":1,"name":"Ardian"},{"id":2,"name":"Ardian"},{"id":3,"name":"Ardian"},{"id":4,"name":"Cek Nama"},{"id":5,"name":"Cek Nama"},{"id":6,"name":"Cek Nama"},{"id":7,"name":"Cek Nama"},{"id":8,"name":"Mas Jan"},{"id":9,"name":"satu"},{"id":10,"name":"Dua"},{"id":11,"name":"Tiga"},{"id":12,"name":"Jiwa"},{"id":13,"name":"Nama2"},{"id":14,"name":"Nama3"},{"id":15,"name":"Nama4"},{"id":16,"name":"Nama5"},{"id":17,"name":"Nama6"}],"queries":[{"query":"select count(*) as aggregate from (select '1' as
row_count
fromauthors
) count_row_table","bindings":[],"time":0.72},{"query":"selectid
,name
fromauthors
","bindings":[],"time":0.64}],"input":[]}
How can I resolve this?
Thanks :)
When I insert this code, it returns to "HTTP". What about this?
if($request->ajax()){
return "AJAX";
}
return "HTTP";
if you tested this on your browser directly, it's normal.
if you want to see the json on standard GET requests, for debug :
if($request['draw'])
{
return $datatable->ajax();
}
SOLUTION 1 Look for this file in your project
vendor/datatables/buttons.server-side.js
The copy it and put it in your assets public folder and then make sure you include it as a scribe before
{{ $dataTable->scripts() }}
so, it should be like this
<script src="{{ url('/') }}/assets/js/buttons.server-side.js"></script>
{{ $dataTable->scripts() }}
and hopefully it will be fixed.
SOLUTION 2 Remove buttons. On your build method in the datatable class, remove buttons by adding something like this
->parameters([
'dom' => 'Bfrtip',
'buttons' => [],
]);
So, the final thing should look like this
public function html()
{
return $this->builder()
->setTableId('users-table')
->columns($this->getColumns())
->minifiedAjax()
->dom('Bfrtip')
->orderBy(1)
-->parameters([
'dom' => 'Bfrtip',
'buttons' => [],
]);
}
CONCLUSION If you still get an error, go to inspect and see if there is any warning. All the best!
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been inactive for 7 days since being marked as stale.