Skip to content
Icon

WARNING You're browsing the documentation for an old version of LARAVEL-DATATABLES. Consider upgrading your project to laravel-datatables 11.0.

Add Column

You can add a custom column on your response by using addColumn api.

Add Column with Blade Syntax

use Datatables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return Datatables::eloquent($model)
->addColumn('intro', 'Hi {{$name}}!')
->make(true);
});

Add Column with Closure

use Datatables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return Datatables::eloquent($model)
->addColumn('intro', function(User $user) {
return 'Hi ' . $user->name . '!';
})
->make(true);
});

Add Column with View

{tip} You can use view to render your added column by passing the view path as the second argument on addColumn api.

use Datatables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return Datatables::eloquent($model)
->addColumn('intro', 'users.datatables.intro')
->make(true);
});

Then create your view on resources/views/users/datatables/intro.blade.php.

Hi {{ $name }}!

Add Column with specific order

{tip} Just pass the column order as the third argument of addColumn api.

use Datatables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return Datatables::eloquent($model)
->addColumn('intro', 'Hi {{$name}}!', 2)
->make(true);
});