英文:
Is there any way to pass the parameter value to Yajra datatable? Please see the code below
问题
以下是您要翻译的内容:
// 控制器
public function admin_dashboard(CollectionDataTable $dataTable1)
{
$from = $to = date('Y-m-d');
$dataTable = $dataTable1->with('from', $from)->with('to', $to)->html();
return view('operation.admin_dashboard', compact('from', 'to', 'dataTable'));
}
public function get_collection_table(CollectionDataTable $dataTable, Request $request)
{
//$from = $to = date('Y-m-d');
return $dataTable->with($request->all())->render('operation.admin_dashboard');
}
// 在路由中
Route::get('/ahsdashdgasdhadgas', 'Operation\BillingDepartmentController@get_collection_table')->name('ahsdashdgasdhadgas');
// Yajra Datatable
public function html()
{
return $this->builder()
->addTableClass('table table-bordered table-secondary table-hover')
->setTableId('collection-table')
->columns($this->getColumns())
->postAjax([
'url' => route('ahsdashdgasdhadgas'),
// 'type' => 'get',
]);
}
如果您需要帮助传递参数以在数据表中使用,请提供更多具体信息以便我可以为您提供指导。
英文:
//Controller
public function admin_dashboard(CollectionDataTable $dataTable1)
{
$from = $to = date('Y-m-d');
$dataTable = $dataTable1->with('from',$from)->with('to',$to)->html();
return view('operation.admin_dashboard',compact('from','to', 'dataTable'));
}
public function get_collection_table(CollectionDataTable $dataTable,Request $request)
{
//$from = $to = date('Y-m-d');
return $dataTable->with($request->all())->render('operation.admin_dashboard');
}
//In route
Route::get('/ahsdashdgasdhadgas', 'Operation\BillingDepartmentController@get_collection_table')->name('ahsdashdgasdhadgas');
//Yajra Datatable
public function html()
{
return $this->builder()
->addTableClass('table table-bordered table-secondary table-hover')
->setTableId('collection-table')
->columns($this->getColumns())
->postAjax([
'url' => route('ahsdashdgasdhadgas'),
//'type' => 'get',
])
}
I can not access the parameter in datatable. Anyone help me to pass parameter in the datatable route so that I can use the parameter for query?
答案1
得分: 0
您可以使用data
选项来传递参数给Yajra数据表:
$builder->postAjax([
'url' => route('users.index'),
'data' => 'function(d) { d.key = "value"; }',
])
附带说明: 您正在使用postAjax
,但您的端点路由类型是GET
。
因此,您可能需要将路由类型更改为POST
:
Route::post(
'/ahsdashdgasdhadgas',
'Operation\BillingDepartmentController@get_collection_table'
)->name('ahsdashdgasdhadgas');
或者,您可以使用构建器的ajax
方法,而不是postAjax
:
$builder->ajax([
'url' => route('users.index'),
'type' => 'GET',
'data' => 'function(d) { d.key = "value"; }',
])
英文:
> How do I pass the parameter in the Yajra data table??
You could make use of the data
option
$builder->postAjax([
'url' => route('users.index'),
'data' => 'function(d) { d.key = "value"; }',
])
Side note: You are using postAjax
but your endpoint route type is GET
.
Hence you may need to change your route type to POST
Route::post(
'/ahsdashdgasdhadgas',
'Operation\BillingDepartmentController@get_collection_table'
)->name('ahsdashdgasdhadgas');
OR instead of postAjax
use the ajax
method of the builder
$builder->ajax([
'url' => route('users.index'),
'type' => 'GET',
'data' => 'function(d) { d.key = "value"; }',
])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论