Pass dynamic params in the ajax call of yii2-grid EditableColum widget

557 views Asked by At

the \kartik\grid\EditableColumn widget has a parameter called ajaxSettings where you may override the parameters passed with the ajax request to the server. What i want to do is to dynamically pass the selected rows ids together with the value coming from the popover to the server. I manage to do that passing static parameter coming from a php array in compile time like so

Editable::widget(['name' => 'publishDate', 'ajaxSettings' => ['ids' => [1,2,3]]])

but It seems that i cannot use a jquery selector there to grab the ids of the selected columns like so

Editable::widget([
    'name' => 'publishDate', 
    'ajaxSettings' => [
        'ids' => '$("#books-grid").yiiGridView("getSelectedRows")'
    ]
])
1

There are 1 answers

2
Leo On

Maybe you want to try creating a variable outside the Editable::widget([ like this:

var arrayIds = $("#books-grid").yiiGridView("getSelectedRows");

And then assign it to the widget:

Editable::widget([
    'name' => 'publishDate', 
    'ajaxSettings' => [
        'ids' => arrayIds
    ]
])

Hope this helps,

Leo.