Ziggi
(Ziggi)
April 2, 2020, 7:37pm
1
There is a general problem with GridView filters.
It’s not uncommon to use GridView inside a form. Good example is a tabbed page, where first tab implement form with main model attributes and next tabs are for related models - and all tabs are within a form, so submit action sends all parameters at once.
GridView is used for information purpose, the end user can evaluate some data in a convenient way while filling forms.
But the problem is with GridView filters!
yii.gridView.js is as follows:
var $form = $('<form/>', {
action: url,
method: 'get',
'class': 'gridview-filter-form',
style: 'display:none',
'data-pjax': ''
}).appendTo($grid);
The filter form element created dynamically is attached to grid element itself what results in nested form!
Why not .appendTo('body');
???
That would result in leaner structure and nested forms would never be created!
samdark
(Alexander Makarov)
April 2, 2020, 10:48pm
3
I guess that’s because there could be multiple forms at the same page.
strtob
(T)
June 22, 2022, 8:49pm
4
is there any workaround or solution for that. In my case, I have the tabbed structure and now problem to use the filters as described by Ziggi
samdark
(Alexander Makarov)
June 23, 2022, 4:47pm
5
Name these forms explicitly.
strtob
(T)
June 27, 2022, 5:48pm
6
Thanks, but how should this work? There is no implementation in the parameter :-/
strtob
(T)
July 7, 2022, 6:16am
7
does anyone have example how to handle this problem?
snathan
(snathan)
July 15, 2022, 7:50pm
9
I have used the below structure for enclosing grid view in the form. I don’t fully understand your use case, but hope this helps.
<?php $form = ActiveForm::begin(['action' => ['/some/index'], 'id' => 'some-form']); ?>
<?= GridView::widget([
....
]); ?>
<?= Html::submitButton('Do something') ?>
<?php ActiveForm::end(); ?>