Struggling with the same thing!!
yajra Laravel Datatables
I want use yajra server side package with the sample code:
$users = User::select(['id','name','email','created_at','updated_at']);
return Datatables::of($users)->make();
I get an "Insuficient parameters" error.
Looking in the implementation of the library, I found the exceptions is thrown because:
public function isLegacyCode($request) { if ( ! $request->get('draw') && $request->get('sEcho')) { throw new \Exception('DataTables legacy code is not supported! Please use DataTables 1.10++ coding convention.'); } elseif ( ! $request->get('draw') && ! $request->get('columns')) { throw new \Exception('Insufficient parameters'); } }
the request is inyected to constructor:
public function __construct(Request $request) { $this->request = $request; $this->isLegacyCode($request); }
I don't know what I'm doing wrong ...
Okay, I fixed it.
The error was being thrown when I was trying to return the Datatables instance with my other view variables, it doesn't work that way.
To fix it, I created a separate function in my controller that is solely responsible for returning the Datatables instance. Then, I set up a route in my routes file that points to the function. The Javascript in the view that initializes the table looks something like this:
$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "route/to/datatables/function"
} );
} );
I'm not the first person to make this mistake, and I know I won't be the last. Hopefully this will help someone else having the same issue.
Please or to participate in this conversation.