SearchPanes Extension
DataTables SearchPanes allows users to filter data by selecting values from a list of options. This documentation covers the server-side SearchPanes API.
Basic Usage
Use the searchPane() API to add search pane options on the response:
use Yajra\DataTables\Facades\DataTables;use App\Models\User; Route::get('user-data', function() { return DataTables::eloquent(User::query()) ->searchPane('status', [ 'Active' => User::where('status', 'active')->count(), 'Inactive' => User::where('status', 'inactive')->count(), ]) ->toJson();});
With Custom Builder Callback
For more complex filtering logic, pass a callback that receives the query builder:
use Yajra\DataTables\Facades\DataTables;use App\Models\User; Route::get('user-data', function() { return DataTables::eloquent(User::query()) ->searchPane('role', [ 'Admin' => 10, 'User' => 50, ], function ($query, $values) { // Custom filter logic when pane value is selected $query->whereIn('role', $values); }) ->toJson();});
Options Format
The options can be passed as:
- Array: Key-value pairs of label => count
- Collection with toArray(): Any
Arrayableobject - Callable: Returns the options dynamically
// Array format'status' => ['active' => 100, 'inactive' => 25] // Callable format'status' => fn() => Status::pluck('name', 'id')->toArray()
See Also
- SearchPanes Configuration - Client-side configuration
- SearchPanes Hide Columns - Exclude columns from panes