![]()
WARNING You're browsing the documentation for an upcoming version of Laravel DataTables. The documentation and features of this release are subject to change.
General Settings
You can customize Laravel DataTables by updating the configuration file. The configuration file is published to config/datatables.php when you run:
php artisan vendor:publish --tag=datatables
Smart Search
Smart search automatically encloses the search keyword with wildcards ("%keyword%"). When enabled, the generated SQL looks like:
column LIKE "%keyword%"
'smart' => true,
Case Insensitive Search
Case insensitive search converts both the column values and search keyword to lowercase before comparison. The generated SQL looks like:
LOWER(column) LIKE LOWER('%keyword%')
'case_insensitive' => true,
Wildcard Search
Wildcard search adds % between every character of the keyword. The generated SQL looks like:
column LIKE "%k%e%y%w%o%r%d%"
'use_wildcards' => false,
[!TIP] When using wildcards with
smartsearch, you only need to add a trailing%:%keyword%
Index Column
The index column name used for DataTables internal row numbering:
'index_column' => 'DT_RowIndex',
Error Handling
Configure how DataTables handles server-side errors. See the Error Handler documentation for full details.
'error' => env('DATATABLES_ERROR', null),
Available options:
null- Display the actual exception message'throw'- Throw a\Yajra\DataTables\Exception- Custom string - Display a custom friendly message
- Translation key - Use a translation key for localization
NULLS LAST SQL
SQL pattern for ordering NULL values last, used by PostgreSQL & Oracle databases:
'nulls_last_sql' => '%s %s NULLS LAST',
[!TIP] For MySQL, use
'-%s %s'as the SQL pattern to push NULLs to the end.
Engines (Advanced)
A list of available DataTables engines. You can register custom engines here:
'engines' => [ 'eloquent' => Yajra\DataTables\Engines\EloquentEngine::class, 'query' => Yajra\DataTables\Engines\QueryBuilderEngine::class, 'collection' => Yajra\DataTables\Engines\CollectionEngine::class,],
[!NOTE] Most users don't need to modify engine settings. Only change these if you're creating a custom DataTables engine.
Builders (Advanced)
Maps data source types to their corresponding engines:
'builders' => [ Illuminate\Database\Eloquent\Relations\HasMany::class => 'eloquent', Illuminate\Database\Eloquent\Builder::class => 'eloquent', Illuminate\Database\Query\Builder::class => 'query', Illuminate\Support\Collection::class => 'collection',],
Complete Configuration Reference
Here's a complete example of the config/datatables.php file:
<?php return [ /* * Smart search adds wildcards automatically */ 'smart' => true, /* * Case insensitive searching */ 'case_insensitive' => true, /* * Wild card character for partial matching */ 'use_wildcards' => false, /* * DataTables internal index column name */ 'index_column' => 'DT_RowIndex', /* * Error message configuration */ 'error' => env('DATATABLES_ERROR', null), /* * NULLS LAST SQL pattern for PostgreSQL & Oracle */ 'nulls_last_sql' => '%s %s NULLS LAST',];
See Also
- Installation - Install and configure the package
- Error Handler - Configure error handling
- Eloquent Data Source - Using Eloquent engine