GridView filter form

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': ''

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!

I guess that’s because there could be multiple forms at the same page.

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

Name these forms explicitly.

Thanks, but how should this work? There is no implementation in the parameter :-/

does anyone have example how to handle this problem?

nobody an idea :frowning:

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(); ?>