Sunday, April 16, 2017

Laravel datatable row details

I am using a single datatable in Laravel 5.4 since it is already implemented in the Laravel framework. My datatable is using query builder to get data, for example using something like this:

@section('content')
<div class="container">
  <table id="services" class="table table-hover table-condensed" style="width:100%">
    <thead>
        <tr>
            <th> </th>
            <th>Id</th>
            <th>Plate</th>
            <th>Brand</th>
            <th>Year</th>

        </tr>
    </thead>
  </table>
</div>

<script type="text/javascript">
$(document).ready(function() {
    table = $('#services').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "",
        "columns": [
            {data: 'id', name: 'id'},
            {data: 'plate', name: 'plate'},
            {data: 'brand', name: 'vehicle.brand'},
            {data: 'year', name: 'vehicle.year'},


        ]
    });    
});  
</script>
@stop

And to get it working proberly, I have to include this file:

<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>

Since datatables are included in Laravel, it takes css from bootstrap, javascript from the datatables package installed in laravel.

Now, reading row detail documentation it is a bit unclear, how can I achieve row details in my case. What do I have to add into the code? Do I have to include some more files?

Same with other features as Edit or Remove buttons for each row. Laravel itself doesn't have documentation for datatables so it is a bit confusing what to do now. Thanks for help.



via Ady96

Advertisement