I'm trying to get datatables working server-side in my laravel project, i have managed to do it on a client side implementation, however, this can only handle 50K rows of data as opposed to 100K+ rows of data when using a server-side implementation.
So my question is HELP!!! I'll explain below :
I used = http://ift.tt/1jnXimp
My Routes
Route::controller('datatables', 'DatatablesController', [
'anyData' => 'datatables.data',
'getIndex' => 'datatables',
]);
My Controller
class DatatablesController extends Controller
{
/**
* Displays datatables front end view
*
* @return \Illuminate\View\View
*/
public function getIndex()
{
return view('datatables.index');
}
/**
* Process datatables ajax request.
*
* @return \Illuminate\Http\JsonResponse
*/
public function anyData()
{
$userCostCode = Auth::user()->CostCode;
$simsdt = Sims::whereRaw( ' left(`Cost Code`, 3) = ? ', [$userCostCode] );
return Datatables::of($simsdt)->make(true);
}
}
My View
<div class="box-body">
<table id="#data-table-large-2" class="display table table-bordered">
<thead>
<tr>
<th> SIM no </th>
<th> Voice Number </th>
</tr>
</thead>
</table>
</div><!-- /.box-body -->
@push('scripts')
<script>
$(function() {
$('#data-table-large-2').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('datatables.data') !!}',
columns: [
{ data: 'SIM no', name: 'SIM no' },
{ data: 'Voice Number', name: 'Voice Number' }
]
});
});
</script>
@endpush
My JSON is coming from datatables/data (route= datatables.data) result below, the stars below would have data there but had to remove it NOT FOR PUBLIC VIEW and replaced with '****secret****' but its just to show i am getting my JSON at the correct url. ```
{
"draw": 0,
"recordsTotal": 320,
"recordsFiltered": 320,
"data": [
{
"ID": 498,
"Item No": 4,
"SIM no": "****secret****",
"Voice Number": "****secret****",
"DH Data Number": "****secret****",
"DE Data Number": null,
"DC Data Number": "****secret****",
"DK Data Number": "****secret****",
"DJ Data Number": null,
```
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire