Best Way To Implement Yajra DataTables in Laravel 9

Yajra DataTables is an Jquery Based Table Viewer which provides advanced control to HTML such as pagination, Search Sorting, and other filters for dynamic data. Datatables is a jQuery extension that allows users to add advanced interaction controls to your HTML table data. Datatables also include ajax support for data search and retrieval. You can provide very fast layouts for searching and sorting by using Datatables.

Yajra DataTables

Just follow the steps to implement datatables in your Laravel application. In this case, I will provide you with the best Method to Implement Yajra DataTables.

Step 1 : Laravel Installation Process

First of all You need to Install Laravel over your Xampp Server or Wamp Server. You have to execute this command inside root Folder given below:

composer create-project --prefer-dist laravel/laravel brotech4u-datatable


Step 2 : Configure Database and other Settings

After Installation of Laravel, You have to configure Database inside the .env file.


Also Read : How To Create Dynamic Sitemap in PHP and MYSQL


Step 3 : Yajra DataTables Installation

For Yajra DataTables, we need to execute Composer Command. Please execute command given below:

composer require yajra/laravel-datatables-oracle:"~9.0"


Step 4 : Insert Dummy Data

I this Step we will create some dummy users with the help of tinker Factory. Here are the commands to create dummy users given below:

php artisan tinker



Step 5 : Create Routes

In this Step , We will create a routes for Yajra DataTables Layout inside routes/web.php file

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('users', [UserController::class, 'index'])->name('users.index');

Also Read : How To Integrate Payumoney Payment Gateway In PHP


Step 6 : Create Controller for Yajra DataTables

In this Step, We wil create a User Controller to manage Layouts and get data request and their return response. The code given below:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use DataTables;

class UserController extends Controller
    public function index(Request $request)
        if ($request->ajax()) {
            $data = User::select('id','name','email')->get();
            return Datatables::of($data)->addIndexColumn()
                ->addColumn('action', function($row){
                    $btn = '<a href="javascript:void(0)" class="btn btn-primary btn-sm">View</a>';
                    return $btn;
        return view('users');


Step 7 : Blade File For View Users Listing

I this Step, We will create a users.blade.php file inside “resources/views/” directory for layout and designs. Html code Given below:

<!DOCTYPE html>
    <title>Yajra DataTables By Brotech4u Tutorial</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="" />
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <script src=""></script>  
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
<div class="container">
    <div class="row">
        <div class="col-12 table-responsive">
            <table class="table table-bordered users">
                        <th width="100px">Action</th>
<script type="text/javascript">
  $(function () {
    var table = $('.users').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('users.index') }}",
        columns: [
            {data: 'id', name: 'id'},
            {data: 'name', name: 'name'},
            {data: 'email', name: 'email'},
            {data: 'action', name: 'action', orderable: false, searchable: false},

Also Read : How To Integrate Payumoney Payment Gateway In Laravel


Step 8 : Start Server

php artisan serve

Now you have to start Laravel Server through command given below:

Now open your Browser and execute this url : http://localhost:8000/users . Here you will get all users lists from the database through Yajra DataTables Library.

Yajra DataTables

For more Information, You can check official documentation at