lundi 5 octobre 2015

Laravel 5 dataTables, initialise table with controller function

I'm trying to create a dataTable of users where each row has a dropdown child-row which contains checkboxes of the user privileges. So quite dynamically a 'super' admin can click on users and assign their privileges within the table.

Firstly, not sure if this is a good idea, so feel free to suggest a better way of doing it. Maybe a simple popup modal per row would be easier but for now I've decided this would be a cool way of doing it so I push on.

Trying to initialise the dataTable with AJAX has me stumped currently however.

PermissionsController.php

public function grid()
{
    //retrieve data from models
    $data['data'] = collect([ 'admins' => $admins, 'roles' => $roles ]);

        return $data;
}

routes.php

Route::get('user-permissions', 'PermissionsController@grid');

permissions.blade

<table class="table table-striped" id="admins_table" >
    <thead>
    <tr>
        <th>Last Name</th>
        <th>First Name</th>
        <th>Email</th>
        <th>Phone</th>
    </tr>
    </thead>
</table>

js

var oTable = $('#admins_table').dataTable( {
    "sDom": "<'row'<'col-md-6'l><'col-md-6'f>r>t<'row'<'col-md-12'p i>>",
    "aaSorting": [],
    "oLanguage": {
        "sLengthMenu": "_MENU_ ",
        "sInfo": "Showing <b>_START_ to _END_</b> of _TOTAL_ entries"
    },
    "ajax": {
       //here's where I'm trying to grab the data
       "url": "http://ift.tt/1MbclpV", 
       "dataSrc": "data"
    },
    "columns": [
        { "data": "last_name" },
        { "data": "first_name" },
        { "data": "email" },
        { "data": "phone" }
    ]
});

I've abstracted out the rest as what's above pertains to the initialisation. Greatly appreciate any help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire