Skip to content
Icon

WARNING You're browsing the documentation for an upcoming version of Laravel DataTables. The documentation and features of this release are subject to change.

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 searched
return DataTables::eloquent(User::query())
->whitelist(['id', 'name', 'email', 'created_at'])
->toJson();

See Also