lundi 9 juillet 2018

Implementing Datatables in Laravel

I want to implement datatables in my laravel project. I already did the steps in installing yajra datatables but it still won't work. Below is my code.

<link href="http://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">

<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src="http://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

This is my code in my controller

public function showListDetails($id){
    $prodList_id = $id;
    $products = DB::table('products')->where('prodList_id', $id)->get();
    return view('users.listDetails')->with('prodList_id', $prodList_id);
}

public function productsDataTable($id){
    $products = DB::table('products')->where('prodList_id', $id)->get();
    return Datatables::of($products)->make(true);
}

This is my route

Route::get('/products/list/{id}', 'UserController@showListDetails')->name('users.showListDetails');
Route::get('/products/list/productsDataTable/{id}', 'UserController@productsDataTable')->name('users.products.productsDataTable');

This is my script

$(document).ready(function() {
$('#productList').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": '{!! url("/users/products/list/productsDataTable/$prodList_id") !!}',

    columns: [
        {data: 'category', name: 'category'},
        {data: 'prod_brand', name: 'prod_brand'},
        {data: 'prod_name', name: 'prod_name'},
        {data: 'prod_qty', name: 'prod_qty'},
        {data: 'prod_price', name: 'prod_price'}
    ]
} );

And this is my table

<table id="productList" class="table table-hover" style="width:100%">
<thead>
    <tr>
        <th>Category</th>
        <th>Product Brand</th>
        <th>Product Name</th>
        <th>Quantity</th>
        <th>Price</th>
    </tr>
</thead>
</table>



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NEoIE3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire