Can you please add ``` before writting code here so that we can check your code
Jul 28, 2017
12
Level 4
Laravel Datatables : 138 Rows and its taking 5 seconds to load, why?
Hey guys, I have been working on this project for the last 6 hours and I cannot figure out for the life of me why it's taking forever for this datatable to load. The more rows I add the longer it takes. I had 300 rows and it took 20 seconds to load. I am using server side and I am also using the yajra/laravel-datatables package. Any help would be greatly appreciated.
View :
<script src="{!! asset('js/plugins/dataTables/datatables.min.js') !!}"></script>
<script>
$(function() {
$('#example')
.on( 'processing.dt', function ( e, settings, processing ) {
$('#processingIndicator').css( 'display', processing ? 'block' : 'none' );
} )
.DataTable( {
responsive: true,
processing: true,
serverSide: true,
ajax: '{{ route("getClients") }}',
deferRender: true,
columns: [
{ data: 'clients_name',
render: function(data, type, full, meta) {
return '<a data-toggle="tab" href="#'+full.id+'">'+data+'</a>';
}
},
{ data: 'clients_email' },
{ data: 'clients_phone' },
{ data: 'clients_address' },
],
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{extend: 'copy'},
{extend: 'csv'},
{extend: 'excel', title: 'Client Database'},
{extend: 'pdf', title: 'Client Database'},
],
} );
});
Controller :
public function getClients()
{
return Datatables::of(Client::select(['id','clients_name','clients_email','clients_phone','clients_address'])->where('user_id', Auth::user()->id))->make(true);
}
Route :
Route::get('/getclients', 'Users\Clients\ClientController@getClients')->name('getClients');
Please or to participate in this conversation.