I'm using this one which seems to work ok. https://github.com/yajra/laravel-datatables-oracle
jQuery Datatables and Laravel Server-side implementation
Hi guys!
I am working on a datatable with more than 16.000 records. If I use Laravel's pagination, it works absolutely fine and with excelent performance. However, I need use the column sorting and "all collumn filtering". Datatables provide these features out of the box. If I use memory pagination of datatable, the performance is terrible, so I will need to use server-side processing:
My question is: anyone has implemented this server-side processing using Eloquent Models and Collections?
I found two plugins, but they are for Laravel 4 and I am using Laravel 5:
I don't know as you guessed, but I'm using Oracle on my project! This plugin worked absolutely fine! Thank you very much!
I'm a Laravel newbie can someone give me an example of how to use the https://github.com/yajra/laravel-datatables-oracle package. I have followed the instructions github but i just get the json information returned. I'm confused on how to get the information to a view and into the table format.
You need to use it in conjunction with http://datatables.net which is a Javascript component that generates the table, populates it and handles the sorting/searching etc.
By default datatables uses local data which is great for small amounts of data but it can also fetch data from a remote source and this is where the Laravel package comes in. This page has more information on hooking it up to a remote source. http://datatables.net/examples/server_side/simple.html
Thanks, just got it working now :) The only thing is when if I use the addColumn as in:
return Datatables::of($users)->addColumn('actions', 'action here')->make(true);
The table populates initially but when an ajax call is made the server returns a 500 error message and the cause is Column not found: 1054 Unknown column 'actions' in 'where clause' , so I assume the script is trying to load this from the database and is ignoring the addColumn on the ajax request.
Am I missing something?
Edit: I was missing something I turned off server-side processing and I achieved the result I was after.
Thank you for you help!
I'm using the https://github.com/yajra/laravel-datatables-oracle package as well. And now I want to use editColumn an modify the appearance of a date. But as mentioned in the documentation, Only applicable if you use Eloquent object.. So how would I make it an Eloquent object?
$rows = DB::table('rows')
->select(array('datetime AS date','datetime AS time', 'licence_plate'))
->where('relation_id','=', $relation[0]->id)
->whereBetween('status', [10, 90]);
return Datatables::of($rows)
->editColumn('date', function($data){ $data->date->toDateTimeString(); })
->editColumn('licence_plate', '<span class="licence_plate">{{ $licence_plate }}</span>')
->addColumn('map', 'map')
->make(true);
But this will give me an Call to a member function toDateTimeString()
@postitief you need to use Carbon manually on your code since your using query builder. And also don't forget to add a return on your closure.
return Datatables::of($rows)
->editColumn('date', function($data){
return with(new Carbon($data->date))->toDateTimeString();
})
->editColumn('licence_plate', '<span class="licence_plate">{{ $licence_plate }}</span>')
->addColumn('map', 'map')
->make(true);
@oakshott did you solve this 500 problem? I've hit it too and raised it as a ticket here
@yajra brother can I cache database query with your package?
Hello everyone. I apologize for the newb question but I just recently started working with Laravel. I am trying to use @yajra Datatable package but I am only getting json output to my screen.
Here is my controller:
public function getOrders()
{
$orders = Orders::select(array(
'id', 'order_date', 'ship_name', 'contact_email', 'contact_phone'
));
return Datatables::of($orders)->make(true);
}
view:
@section('content')
<table class="table table-bordered table-hover" id="orders-table">
<thead>
<tr>
<th>Order ID</th>
<th>Order Date</th>
<th>Customer Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
</table>
@endsection
@push('scripts')
<script type="text/javascript">
$('#orders-table').DataTable({
"processing": true,
"serverSide": true,
"ajax": '{!! route('orders.getorders') !!}',
"columns": [
{ data: 'id', name: 'id' },
{ data: 'order_date', name: 'order_date' },
{ data: 'ship_name', name: 'ship_name' },
{ data: 'contact_email', name: 'contact_email' },
{ data: 'contact_phone', name: 'contact_phone' }
]
});
</script>
@endpush
route:
Route::get('filterfetch/orders', [
'as' => 'orders.getorders', 'uses' => 'Orders\OrdersController@getOrders'
]);
I have also added the following to my master layout:
<!-- Datatables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
Any suggestions would be greatly appreciated.
@yajra I'm trying to use your package, but something is missing somewhere. When I try to output the table to my view all I get is JSON. All the rest of my view is missing except for the JSON code. Am I missing something?? Any help from anyone would be appreciated, I have already spent too long trying to get this to work.
Ok, I have been able to get this to load by using the service method. Not sure what was wrong with the other way but this works and thats all I care about.
@smccoy78, you need two routes for it to work. First route is for displaying the table view and the 2nd route is for processing dataTables json response.
On your example, getOrders is only for processing the json response. You need to add additional route like getIndex and load the appropriate view.
When using service approach, the package detects the response you wanted which is the reason why it works for you on a single route.
@yajra , thanks! I actually got it working yesterday doing that exact thing. I had tried that previously, but it wasn't working. Not sure what I did different yesterday.
I ditched the packages and used the Datatables PHP Library, this gives me much more functionality.
Please or to participate in this conversation.