1
I am using Jquery Datatables in a small system and everything was fine until I came across a listing of almost 2500 records...
The point is that it takes a certain amount of time for the information to be loaded and adjusted in Datatable, which causes it to keep loading and displaying all 2500 records on the page until it loads everything and the paging goes into action.
Is there any way to avoid/mask it? I don’t currently use ajax, I do so:
In my Controller:
public function index()
{
$funcoes = Funcao::orderBy('id')->get();
return view('cadastros/funcao/index', compact('funcoes'));
}
In my View:
<table id="appDatatable" class="table table-bordered table-hover">
<thead><tr><th>...</th></tr></thead>
<tbody>
@foreach($funcoes as $funcao)
<tr>
<td>{{ $funcao->cbo }}</td>
<td>{{ $funcao->nome }}</td>
...
</tr>
@endforeach
</tbody>
</table>
My script:
<script>
$(function () {
$("#appDatatable").DataTable({
sPaginationType: "simple_numbers",
});
});
</script>
An option would be to load the user’s events/interactions with the table. https://datatables.net/examples/data_sources/server_side.html
– Marconi
Loading 2500 records at once is not wise, why not use Server-side Processing? https://datatables.net/examples/data_sources/server_side.html
– Paulo
I n use because I don’t even know rs, I’ll take a look at this link and see if I can do here
– Raylan Soares
In case I am using Laravel5, in the part that calls the ajax I put a route that returns all the elements in JSON and it makes this thing to load only what you need?
– Raylan Soares
The ajax call is inside the . Datatable? method or you fill in the <table> first and then use $('#table'). Datatable()?
– Eduardo Moreira
Yeah, I’ll fill it in and then call
– Raylan Soares
edits the question and puts the javascript of the ajax call and . Datatable()
– Eduardo Moreira
I put what I do currently @Eduardomoreira
– Raylan Soares
Look, this slowness is probably in the writing of the table, and not in you turning it into Datatable (in my experience this is very fast). I suggest you test without turning it into Datatable to confirm where the problem is.
– Eduardo Moreira
Yes, apparently it is slow by its much same thing, also it took a long time without Datatable, I will try to do what they said with the server side.
– Raylan Soares