Laravel Datatable Dropdown Search Example

Admin   Laravel   147  2021-03-16 00:40:07

Hi Guys,

In this Tutorial,I will learn you how to ue datatable dropdown search in laravel.You can easy and simple use datatable dropdown filter in laravel.

We would love to share with you how to add custom date filter and custom input search field and without display data without page refresh on datatables.

Laravel yajra datatables provide default global search, in that search it will search entire row of table. But if you need to add for only one specific column like for created date search with datepicker or status with dropdown then you must have to implement custom filtering in your datatable.

DataTables is a plug-in for the jQuery Javascript library. Laravel Yajra DataTables Package provide many functionalities like searching, sorting, pagination on table.

Step 1: Install Laravel 7

In this step,you can install laravel 7 application. So run bellow command and get clean fresh laravel 7 application.

 

composer create-project --prefer-dist laravel/laravel blog

Step 2: Install Yajra Datatable

We need to install yajra datatable package.so you can install using following command:

 

composer require yajra/laravel-datatables-oracle

After that you need to set providers and alias.

 

.....

'providers' => [

....

Yajra\DataTables\DataTablesServiceProvider::class,

]

'aliases' => [

....

'DataTables' => Yajra\DataTables\Facades\DataTables::class,

]

.....

Step 3: Add Dummy Records

we will create some dummy users using tinker factory. so let's create dummy records using bellow command:

 

php artisan tinker

factory(App\User::class, 200)->create();

Step 4: Add Route

In this step,you can create route for datatale layout file data.

routes/web.php

 

Route::get('users', ['uses'=>'[email protected]', 'as'=>'users.index']);

Step 5: Create Controller

In this step,you can create to usercontroller.this controller mange to getting data and layout for datatable.

app/Http/Controllers/UserController.php