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.

Order Columns

In some cases, you may want to use a custom order sql for a set of columns. To achieve this, you can use orderColumns api.

Special Variable & Placeholder

  • orderColumns has a special variable $1 which will be replaced with the order direction of the column.
  • orderColumns has a special placecholder :column which will be replaced with the column name set in the first parameter.

Example

In this example, we will order the column name with nulls as last result.

use DataTables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return DataTables::eloquent($model)
->orderColumns(['name', 'email'], '-:column $1')
->toJson();
});