eloquent($query)
->addColumn('action', function ($data) {
return view('user::users.partials.actions', compact('data'));
});
}
/**
* Get query source of dataTable.
*
* @param \App\Models\User $model
* @return \Illuminate\Database\Eloquent\Builder
*/
public function query(User $model)
{
return $model->newQuery();
}
/**
* Optional method if you want to use html builder.
*
* @return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->setTableId('users-table')
->columns($this->getColumns())
->minifiedAjax()
->dom("<'row'<'col-md-3'l><'col-md-5 mb-2'B><'col-md-4'f>> .
'tr' .
<'row'<'col-md-5'i><'col-md-7 mt-2'p>>")
->orderBy(1)
->buttons(
Button::make('excel')
->text(' Excel'),
Button::make('print')
->text(' Print'),
Button::make('reset')
->text(' Reset'),
Button::make('reload')
->text(' Reload')
);
}
/**
* Get columns.
*
* @return array
*/
protected function getColumns()
{
return [
Column::make('id'),
Column::make('created_at'),
Column::make('updated_at'),
Column::computed('action')
->exportable(false)
->printable(false)
->addClass('text-center'),
];
}
/**
* Get filename for export.
*
* @return string
*/
protected function filename()
{
return 'Users_' . date('YmdHis');
}
}