The Bndr
The Bndr

Reputation: 13394

Split pjax wiget in form part and result part

I'm using Yii2, activeForm and the Yii2 pjax widget to handle an search form with result list.

But for layout reason, I have to split this package to two parts: the search form, which should be located in the header of the page and the result listing, which should be placed in the middle of the page.

This means it's not possible to do something like that (pseudocode):

Pjax::begin
 $form=>activeForm::begin..
 ActiveForm::end(); 
 ListView::widget...
Pjax::end()

What I need is placing the activeForm in the layout header, placing the ListView wiget in the center of the page and telling pjax: read the input from the form, load data from Server and replace the clist view. Is that possible using the build-in functionality of the widgets?

I didn't get it working, maybe I misunderstood the basic concept?

Upvotes: 0

Views: 40

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133380

Using gridview (or widget which use searchModel) you could use a separated model for modelSearch in header and show the resul in the gridview palced where you prefer

in this way you need only a pjax block

<?= $this->render('_search', ['model' => $searchModel]); ?>

<?php Pjax::begin(); ?>

<?= GridView::widget([

    ...

]); ?>

<?php Pjax::end(); ?>

for other soluzione not based on gridview and when you need multiple seprataed pjax block

You could try using named pjax block using a value for id

<?php \yii\widgets\Pjax::begin(['id'=>'pjax-block1']); ?>
.... 
....
<?php \yii\widgets\Pjax::end(); ?>    


<?php \yii\widgets\Pjax::begin(['id'=>'pjax-block2']); ?>
....
....
<?php \yii\widgets\Pjax::end(); ?>    

and if you need you could manage specific refresh using jquery

$.pjax.reload({container: '#pjax-block1', async: false});
$.pjax.reload({container: '#pjax-block2', async: false});

Upvotes: 0

Related Questions