Extended DataTable

We can now extend and reuse our DataTable class inside our controller by using before and response callback.

IMPORTANT: Extended DataTable is only applicable on ^1.1 and above.

Upgrading from v1.0 to v1.1

    public function ajax()
        return $this->datatables
            ->addColumn('action', 'path.to.action.view')


    public function dataTable()
        return $this->datatables
            ->addColumn('action', 'path.to.action.view');

Quick Example:

Route::get('datatable', function(RolesDataTable $dataTable){
   return $dataTable->before(function (\Yajra\DataTables\DataTableAbstract $dataTable) {
       return $dataTable->addColumn('test', 'added inside controller');
   ->response(function (\Illuminate\Support\Collection $response) {
       $response['test'] = 'Append Data';

       return $response;
   ->withHtml(function(\Yajra\DataTables\Html\Builder $builder) {
        $builder->columns(['id', 'name', 'etc...']);
   ->with('key', 'value')
    'key2' => 'value2',
    'key3' => 'value3',