有没有办法将参数值传递给Yajra数据表?请参阅下面的代码。

huangapple go评论58阅读模式
英文:

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"; }',
])

Documentation


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"; }',
])

huangapple
  • 本文由 发表于 2023年6月15日 16:23:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76480509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定