141 lines
3.7 KiB
PHP
141 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\DataTables;
|
|
|
|
use Yajra\DataTables\Html\Button;
|
|
use Yajra\DataTables\Html\Column;
|
|
use Yajra\DataTables\Html\Editor\Editor;
|
|
use Yajra\DataTables\Html\Editor\Fields;
|
|
use Yajra\DataTables\Services\DataTable;
|
|
|
|
class ParentDataTable extends DataTable
|
|
{
|
|
/**
|
|
* Build DataTable class.
|
|
*
|
|
* @param mixed $query Results from query() method.
|
|
* @return \Yajra\DataTables\DataTableAbstract
|
|
*/
|
|
public function dataTable($query)
|
|
{
|
|
return $this->addButtons(datatables()->eloquent($query));
|
|
}
|
|
|
|
/**
|
|
* Add buttons DataTable class.
|
|
*
|
|
* @param mixed $query Results from query() method.
|
|
* @return \Yajra\DataTables\DataTableAbstract
|
|
*/
|
|
public function addButtons($datatables)
|
|
{
|
|
return $datatables->addColumn('action', $this->getHtmlButtons());
|
|
}
|
|
|
|
public function getHtmlButtons()
|
|
{
|
|
$buttons = '';
|
|
// $buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-secondary btn-show mr-2"><i class="fa fa-fw fa-eye"></i></button>';
|
|
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-pencil-alt"></i></button>';
|
|
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-fw fa-trash"></i></button>';
|
|
return $buttons;
|
|
}
|
|
|
|
public function makeColumnButtons()
|
|
{
|
|
return Column::computed('action')
|
|
->exportable(false)
|
|
->printable(false)
|
|
->searchable(false)
|
|
->width(80)
|
|
->addClass('text-center');
|
|
}
|
|
|
|
/**
|
|
* Get query source of dataTable.
|
|
*
|
|
* @param \App\Family $model
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function buildQuery($model)
|
|
{
|
|
return $model->newQuery();
|
|
}
|
|
|
|
|
|
/**
|
|
* Optional method if you want to use html builder.
|
|
*
|
|
* @return \Yajra\DataTables\Html\Builder
|
|
*/
|
|
public function html()
|
|
{
|
|
return $this->buildHtml(strtolower($this->model_name) . '-table');
|
|
}
|
|
|
|
/**
|
|
* Optional method if you want to use html builder.
|
|
*
|
|
* @return \Yajra\DataTables\Html\Builder
|
|
*/
|
|
public function buildHtml($id)
|
|
{
|
|
return $this->builder()
|
|
->setTableId($id)
|
|
->parameters($this->getParameters())
|
|
->columns($this->getColumns())
|
|
->minifiedAjax()
|
|
->dom($this->getDom())
|
|
->orderBy(0,'asc')
|
|
->buttons($this->getDatatablesButtons());
|
|
}
|
|
|
|
public function getParameters()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getDatatablesButtons()
|
|
{
|
|
$buttons = [];
|
|
$buttons[] = Button::make('export');
|
|
$buttons[] = Button::make('print');
|
|
return $buttons;
|
|
}
|
|
|
|
public function getDom()
|
|
{
|
|
$dom = $this->getDatatablesHeaderDefault();
|
|
$dom .= "rt";
|
|
$dom .= $this->getDatatablesFooterDefault();
|
|
return $dom;
|
|
}
|
|
|
|
public function getDatatablesHeaderDefault() {
|
|
return "<'row dt-toolbar-header'<'col-lg-4'l><'col-lg-4'B><'col-lg-4 text-right add'f>>";
|
|
}
|
|
|
|
public function getDatatablesFooterDefault() {
|
|
return "<'row dt-toolbar-footer'<'col-md-6'i><'col-md-6'p>>";
|
|
}
|
|
|
|
/**
|
|
* Get filename for export.
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function filename()
|
|
{
|
|
return self::buildFilename($this->model_name);
|
|
}
|
|
|
|
/**
|
|
* Get filename for export.
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function buildFilename($models_name)
|
|
{
|
|
return $models_name . '_' . date('YmdHis');
|
|
}
|
|
} |