Laravel 5.5 – Yajra Datatable Example

Laravel 5.5 – Yajra Datatable Example

In this post we will give you information about Laravel 5.5 – Yajra Datatable Example. Hear we will give you detail about Laravel 5.5 – Yajra Datatable ExampleAnd how to use it also give you demo for it if it is necessary.

Today, we are share with youu how to implement yajra datatable in laravel application with example. in your application sorting, searching and pagination functionality is common if you use simple table for display your application data iin tabuler forrmate so you should also write manualy for it all functionality. and it is very painful and take some time.


But, if you use yajra datatable package in your laravel application then you can save this time. because yajra datatable jquery package provide all those functionality ready made nothing else write of single line for it.


yajra datatable provide following functionality for data display in tabuler formate. here listing some basic and core functionality of yajra datatable


1. Pagination2. Full Searching3. Data Sorting4. Data Export, Print


After done this tutorials and you run it your output look like this.



Install Package


First, we need to install yajra/laravel-datatables-oracle package in our laravel application run by following command in terminal.




composer require yajra/laravel-datatables-oracle



Configure Package


Next, configure installed package in application. so, open your config/app.php file and set insstalled package service providers and aliases.




'providers' => [
    ...,
    YajraDataTablesDataTablesServiceProvider::class,
]

'aliases' => [
    ...,
    'DataTables' => YajraDataTablesFacadesDataTables::class,
]



After set providers and aliases then publish vendor run by following command.




php artisan vendor:publish
	


Add Dummy Data


Next, we are add some dummy data in users table because we are use this data in datatable tabuler formate for demo.




php artisan tinker
>>> factory(AppUser::class, 50)->create();
	


Create Routes


Next, we need to create following two route. so, open your routes/web.php and create following two route.




// Display view
Route::get('datatable', 'DataTableController@datatable');
// Get Data
Route::get('datatable/getdata', 'DataTableController@getPosts')->name('datatable/getdata');
	



Create Controller


Next, create DataTableController.php file in app/Http/Controllers folder




namespace AppHttpControllers;

use IlluminateHttpRequest;
use IlluminateSupportFacadesInput;
use Redirect;
use DataTables;
use AppUser;

class DataTableController extends Controller
{    
    public function datatable()
    {
        return view('datatable');
    }

    public function getPosts()
    {
        return DataTables::of(User::query())->make(true);
    }
}



Create Blade File


Next, create datatable.blade.php file in resources/views/ folder and copy past following .


Info Message!!
#First check jQuery should be add in head section..




@extends('layouts.app')

@section('style')
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet">
@endsection

@section('content')
<div >
    <div >
        <div >
            <div >
                <div >Data Table Demo</div>

                <div >
                    <table  style="width:100%">
                        <thead>
                            <tr>
                                <th>Id</th>
                                <th>Name</th>
                                <th>Email</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('script')
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('.datatable').DataTable({
        processing: true,
        serverSide: true,
        ajax: '{{ route('datatable/getdata') }}',
        columns: [
            {data: 'id', name: 'id'},
            {data: 'name', name: 'name'},
            {data: 'email', name: 'email'},
        ]
    });
});
</script>
@endsection
	


Now we are ready to run our example so run bellow command ro quick run:



php artisan serve


Now you can open bellow URL on your browser:



http://localhost:8000/datatable


If you want to any problem then please write comment and also suggest for new topic for make tutorials in future. Thanks…

Hope this and post will helped you for implement Laravel 5.5 – Yajra Datatable Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  49  =  53

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US