如何将 ( 等 ) 之类的参数传递res_id
给resname
( DataTable Service Class
)RestaurantDataTable
以进行自定义数据库查询,例如 ( get only restaurant whereid = x
等resname = xxx
)?
餐厅控制器:
use App\DataTables\restaurantDataTable;
class restaurantController extends AppBaseController
{
public function index(restaurantDataTable $restaurantDataTable)
{
return $restaurantDataTable->render('restaurant.index');
}
}
餐厅数据表:
class restaurantDataTable extends DataTable
{
/**
* @return \Illuminate\Http\JsonResponse
*/
public function ajax()
{
return $this->datatables
->eloquent($this->query())
->addColumn('action', 'restaurant.datatables_actions')
->make(true);
}
/**
* Get the query object to be processed by datatables.
*
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
*/
public function query()
{
$restaurants = restaurant::query();
return $this->applyScopes($restaurants);
}
/**
* Optional method if you want to use html builder.
*
* @return \Yajra\Datatables\Html\Builder
*/
public function html()
{
return $this->builder()
->columns($this->getColumns())
->addAction(['width' => '10%'])
->ajax('')
->parameters([
'dom' => 'Blfrtip',
'scrollX' => false,
'buttons' => [
'print',
'reset',
'reload',
[
'extend' => 'collection',
'text' => '<i class="fa fa-download"></i> Export',
'buttons' => [
'csv',
'excel',
'pdf',
],
],
'colvis'
]
]);
}
/**
* Get columns.
*
* @return array
*/
private function getColumns()
{
return [
'res_name' => ['name' => 'res_name', 'data' => 'res_name'],
'res_address' => ['name' => 'res_address', 'data' => 'res_address'],
'res_state' => ['name' => 'res_state', 'data' => 'res_state'],
'res_location' => ['name' => 'res_location', 'data' => 'res_location'],
'res_area' => ['name' => 'res_area', 'data' => 'res_area']
];
}
/**
* Get filename for export.
*
* @return string
*/
protected function filename()
{
return 'restaurant';
}
}
Table.blade.php:
@section('css')
@include('layouts.datatables_css')
@endsection
{!! $dataTable->table(['width' => '100%']) !!}
@section('scripts')
@include('layouts.datatables_js')
{!! $dataTable->scripts() !!}
@endsection
我需要自定义UsersDataTable
类public function custom_query($param) {}
中的函数public function custom_ajax($param) {}
吗?