Laravel 5.8 Datatables Server Side Processing

Today, We want to share with you Laravel 5.8 Datatables Server Side Processing.In this post we will show you Laravel server side processing for Datatables, hear for jQuery Datatables and Laravel Server-side implementation we will give you demo and example for implement.In this post, we will learn about DataTables – Server-side Processing in Laravel using Yajra with an example.

Laravel 5.8 Datatables Server Side Processing

There are the Following The simple About Laravel 5.8 Datatables Server Side Processing Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 5.8 datatables server side processing, so the laravel datatables server side pagination for this example is following below.

Implement DataTables server-side in laravel

include Datatables CSS file

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.12/datatables.min.css"/>

<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.12/datatables.min.js"></script>

HTML table

<div class="dsp panel-head"> 
<div class="panel-body">   
 <div class="row">         
 <table class="table table-bordered" id="company_table" style="width:100%">
	<thead>
			<th>Id</th>
			<th>Member First Name</th>
			<th>Member Last Name</th>
			<th>Information</th>
			<th>Age</th>
			<th>Action</th>
	</thead>        
 </table> 
</div>
</div>

</div>

add javascript code

<script>

      $(document).ready(function(){

        // Data table for serverside

       $('#company_table').DataTable({

            "processing": true,

            "serverSide": true,

            "ajax":{

                     "url": "{{ url('allmembersList') }}",

                     "dataType": "json",

                     "type": "POST",

                     "data":{ _token: "{{csrf_token()}}",route:'members'}

                   },

            "columns": [

                { "data": "id" },

                { "data": "m_first_name" },
{ "data": "m_last_name" },
{ "data": "information" },
{ "data": "m_age" },

                { "data": "action" }

            ],

            aoColumnDefs: [

            {

               bSortable: false,

               aTargets: [ -1 ]

            }

          ]  



        });
});
</script>

create Laravel routes

Route::get('members','[email protected]');
Route::post('allmembersList','[email protected]');

create member model file

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Member extends Model
{
    
protected $table = 'members';
protected $fillable = ['m_first_name','m_last_name','m_age','information'];
}

create Demo controller file

app/Http/Controllers/MemberController.php

<?php
namespace App\Http\Controllers;


use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use PDF;
use App\Members;


class MemberController extends Controller
{

   
    function members(Request $request){
        return view('show_member_list');
    }
    function allmembersList(Request $request){

       $columns = array( 
            0 =>'id', 
            1 =>'m_first_name',
            2 =>'m_last_name',
            3 =>'information',
            4 =>'m_age',
        );  
        $memberData = Members::count();            
        $filter_member = $memberData;
        $limit = $request->input('length');
        $start = $request->input('start');
        $order = $columns[$request->input('order.0.column')];
        $dir = $request->input('order.0.dir');
            
        if(empty($request->input('search.value')))
        {            
            $companys = Members::offset($start)
                         ->limit($limit)
                         ->orderBy($order,$dir)
                         ->get();
        }else {
            $search = $request->input('search.value'); 

            $companys =  Members::where('id','LIKE',"%{$search}%")
                            ->orWhere('m_first_name', 'LIKE',"%{$search}%")
->orWhere('m_last_name', 'LIKE',"%{$search}%")
->orWhere('m_age', 'LIKE',"%{$search}%")
                            ->offset($start)
                            ->limit($limit)
                            ->orderBy($order,$dir)
                            ->get();

            $filter_member = Members::where('id','LIKE',"%{$search}%")
                             ->orWhere('m_first_name', 'LIKE',"%{$search}%")
->orWhere('m_last_name', 'LIKE',"%{$search}%")
->orWhere('m_age', 'LIKE',"%{$search}%")
                             ->count();
        }
        $data = array();
        if(!empty($companys))
        {
            foreach ($companys as $key=>$company)
            {
                
                $submemberList['id'] = $key+1;
                $submemberList['m_first_name'] = $company->m_first_name;
                $submemberList['m_last_name'] = $company->m_last_name;
                $submemberList['m_age'] = $company->m_age;
                $submemberList['information'] = $company->information;
                $submemberList['action'] = '<a href="#" class="del"><span class="glyphicon glyphicon-trash"></span> 
</a><a href="#" class="edit"><span class="glyphicon glyphicon-edit"></span></a>';
                $data[] = $submemberList;
            }

        }
        $member_data = array(
        "draw"            => intval($request->input('draw')),  
        "recordsTotal"    => intval($memberData),  
        "recordsFiltered" => intval($filter_member), 
        "data"            => $data   
        );            
        echo json_encode($member_data); 
     }          
        
 
}

?>

Web Programming Tutorials Example with Demo

Read :

Read Also:  Laravel Datatables edit Column HTML Source Code render

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.8 Datatables Server Side Processing.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.