White Listing Columns
The whitelist feature allows you to explicitly define which columns can be used for sorting and searching. Only columns defined in the whitelist will be searchable and sortable.
Basic Usage
use Yajra\DataTables\Facades\DataTables;use App\Models\User; Route::get('user-data', function() { $model = User::query(); return DataTables::eloquent($model) ->whitelist(['name', 'email']) ->toJson();});
Common Use Cases
Limit Searchable Columns
return DataTables::eloquent(User::query()) ->whitelist(['name', 'email', 'status']) ->toJson();
Performance Optimization
// Only index columns will be sorted and searchedreturn DataTables::eloquent(User::query()) ->whitelist(['id', 'name', 'email', 'created_at']) ->toJson();
See Also
- Black Listing Columns - Disable sorting/searching on specific columns
- Column Configuration - Column attributes