Posted inTechnology / JavaScript / jQuery / Laravel

Laravel Custom Dropdown Server Side Filter in Datatables

Today, We want to share with you Laravel Custom Dropdown Server Side Filter in Datatables.In this post we will show you PHP Laravel DataTable Custom Filter Server Side, hear for php Laravel Filtering Datatables through a dropdown list we will give you demo and example for implement.In this post, we will learn about custom laravel filter datatable serverside with an example.

Laravel Custom Dropdown Server Side Filter in Datatables

There are the Following The simple About Laravel Custom Dropdown Server Side Filter in Datatables Full Information With Example and source code.

As I will cover this Post with live Working example to develop Create Custom Dropdown Server Side Filter in Datatables, so the some major files and Directory structures for this example is following below.

Create Custom Dropdown Server Side Filter in Datatables

Step 1 : Laravel custom dropdown server-side filter

HTML Table source code with empty table body (tbody)

    
ID Member Name Member Email Mobile Prorities

Step 2 : Include CDN

CSS CDN into the head tag in Laravel Project

    

Include Before closing body part

    

Step 3 : server-side datatable

Ajax call server-side datatable

    var dtListMembers = $("#dtListMembers").DataTable({
      "processing": true,
      "serverSide": true,
      "ajax": Laravel.appURL+'/members/json',
      "columns": [
        {
          data: 'id'
        },
        {
          data: 'membername'
        },
        {
          data: 'email'
        },
        {
          data: 'mobile'
        },
        {
          data: 'prorities'
        },
      ]
      ...
    });

Make the filter dropdown

    

jquery on change event

    $('#proritiesFilter').on('change', function(){
      var filter_value = $(this).val();
      var liveurl = Laravel.appURL+'/member/json/'+filter_value;
      dtListMembers.ajax.url('+liveurl+').load();
    });

Step 4 : Laravel Register routes

routes/web.php

    // Route for list of members in json format
    Route::get('/member/json', 'MemberController@json')->middleware('ajax');
    // Route for list of members with specific prorities in json format
    Route::get('/member/json/{prorities}', 'MemberController@json')->middleware('ajax');

Step 5 : Create Laravel controller

Laravel Handle jquery ajax request in the controller

    public function json(Request $request)
    {
      if($request->prorities) {
        $members = Member::where('prorities',$request->prorities)->get();
        return response()->json(['data' => $members]);
      } else {
        $members = Member::get();
        return response()->json(['data' => $members]);
      }
    }
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

I hope you get an idea about Laravel Custom Dropdown Server Side Filter in Datatables.
I would like to have feedback on my Pakainfo.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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype