2023-06-04 14:09:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Master\DataTables;
|
|
|
|
|
2023-06-08 17:21:49 +00:00
|
|
|
use Modules\Master\Entities\SubDistrict;
|
2023-06-04 14:09:39 +00:00
|
|
|
use Yajra\DataTables\Html\Column;
|
|
|
|
use Yajra\DataTables\Services\DataTable;
|
|
|
|
|
|
|
|
class SubDistrictDataTable extends DataTable
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Build DataTable class.
|
|
|
|
*
|
|
|
|
* @param mixed $query Results from query() method.
|
|
|
|
*
|
|
|
|
* @return \Yajra\DataTables\DataTableAbstract
|
|
|
|
*/
|
|
|
|
public function dataTable($query)
|
|
|
|
{
|
|
|
|
|
2023-06-08 17:21:49 +00:00
|
|
|
$query = SubDistrict::with('district.city.province.country');
|
|
|
|
|
2023-06-04 14:09:39 +00:00
|
|
|
return datatables()
|
|
|
|
->eloquent($query)
|
|
|
|
->filter(function ($query) {
|
|
|
|
$search = request()->get('search');
|
|
|
|
if ($search['value'] !== "") {
|
|
|
|
$query->where('name', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhere('postal_code', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhere('district_id', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhere('code', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhere('status', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhereRelation('district', 'name', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhereRelation('district.city', 'name', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhereRelation('district.city.province', 'name', 'like', "%" . $search['value'] . "%")
|
|
|
|
->orWhereRelation('district.city.province.country', 'name', 'like', "%" . $search['value'] . "%");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
->addIndexColumn()
|
|
|
|
->addColumn('status', function ($model) {
|
2023-06-08 17:21:49 +00:00
|
|
|
return view('master::sub-district._status', compact('model'));
|
2023-06-04 14:09:39 +00:00
|
|
|
})
|
|
|
|
->addColumn('action', function ($model) {
|
2023-06-08 17:21:49 +00:00
|
|
|
return view('master::sub-district._action', compact('model'));
|
|
|
|
})
|
|
|
|
->rawColumns(['status', 'action']);
|
2023-06-04 14:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get query source of dataTable.
|
|
|
|
*
|
|
|
|
* @param \Modules\Master\Entities\District $model
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
|
|
*/
|
2023-06-08 17:21:49 +00:00
|
|
|
public function query(SubDistrict $model)
|
2023-06-04 14:09:39 +00:00
|
|
|
{
|
|
|
|
return $model->newQuery();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional method if you want to use html builder.
|
|
|
|
*
|
|
|
|
* @return \Yajra\DataTables\Html\Builder
|
|
|
|
*/
|
|
|
|
public function html()
|
|
|
|
{
|
|
|
|
return $this->builder()
|
2023-06-08 17:21:49 +00:00
|
|
|
->setTableId('master-sub-district-table')
|
2023-06-04 14:09:39 +00:00
|
|
|
->columns($this->getColumns())
|
|
|
|
->minifiedAjax()
|
2023-06-08 17:21:49 +00:00
|
|
|
->orderBy(5, 'asc')
|
2023-06-04 14:09:39 +00:00
|
|
|
->stateSave(false)
|
|
|
|
->responsive()
|
|
|
|
->autoWidth(false)
|
|
|
|
->parameters([
|
|
|
|
'scrollX' => false,
|
|
|
|
'drawCallback' => 'function() { KTMenu.createInstances(); }',
|
|
|
|
])
|
|
|
|
->addTableClass('align-middle table-row-dashed fs-6 gy-5');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get columns.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getColumns()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false),
|
|
|
|
Column::make('district.city.province.country.name')->title(__('Country')),
|
|
|
|
Column::make('district.city.province.name')->title(__('Province')),
|
|
|
|
Column::make('district.city.name')->title(__('City')),
|
|
|
|
Column::make('district.name')->title(__('District')),
|
|
|
|
Column::make('code')->title(__('Code')),
|
|
|
|
Column::make('name')->title(__('Name')),
|
|
|
|
Column::make('postal_code')->title(__('Postal Code')),
|
2023-06-08 17:21:49 +00:00
|
|
|
Column::computed('status')->title(__('Status'))->width(50)->addClass('text-center')->exportable(false),
|
2023-06-04 14:09:39 +00:00
|
|
|
Column::computed('action')
|
|
|
|
->exportable(false)
|
|
|
|
->printable(false)
|
2023-06-06 14:49:56 +00:00
|
|
|
->width(100)
|
2023-06-04 14:09:39 +00:00
|
|
|
->addClass('text-center')
|
|
|
|
->responsivePriority(-1),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get filename for export.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function filename()
|
|
|
|
: string
|
|
|
|
{
|
|
|
|
return 'Sub_District_' . date('YmdHis');
|
|
|
|
}
|
|
|
|
}
|