Have you tried this package https://github.com/yajra/laravel-datatables ?
Laravel 5 + DataTables ajax call
Hello all,
I'm trying to use ajax to populate my data table but can't get anything other than "No data available in table". Using the basic initialisation I can get it all working fine. I pass through a php object from a controller and iterate out the rows.
But I want to use a json object to initialise it instead. I've created a route that calls a controller function and returns a collection. If I simply type in the route it returns it as a json output in the browser.
{"data": {"admins": [{ "id": 61, "email": "example@gmail.com", "first_name": "Gary", "last_name": "barlow", "phone": "123" //and so on
Here's the javascript snippet that's relevant:
var table = $("example").DataTable({
ajax: {
url: '/user-permissions',
dataSrc: 'data.admins'
}
columns: [
{ data: 'first_name' }
{ data: 'last_name' }
{ data: 'email' }
{ data: 'phone' }
]
});
As I've said the table displays "No data available in table" so it is initialising it's just not reading the json. I'm not sure how to correctly declare the route url. Any help is greatly appreciated!
Please or to participate in this conversation.