Hello folks!
I hope someone can help me solve a pagination issue, as I can’t find any post that describes how to deal with this.
The case is that I have a search form, where I search for stores (search.php). When I hit the search button, an ajax request is sent to my controller, and the matching stores are listed in a separate view by using renderPartial (_searchResult.php). Everything is displayed as expected, but something is wrong with the pagination. A non-ajax get request is sent to my controller when I click "next", causing only a blank page to appear. How do I get the pagination links to use ajax, as expected?
Controller code:
public function actionSearch()
{
$model = new StoreSearchForm();
if(Yii::app()->request->isAjaxRequest)
{
if(isset($_POST['StoreSearchForm']))
{
$model->attributes=$_POST['StoreSearchForm'];
$model->SearchResult = new CArrayDataProvider(Store::model()->search($model->SearchString), array(
'pagination'=>array(
'pageSize'=>15
)
));
$this->renderPartial('_searchResult',array('dataProvider'=>$model->SearchResult), false, true);
Yii::app()->end();
}
}
$this->render('search',array('model'=>$model));
}
view search.php:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'store-search-form',
'enableAjaxValidation'=>false,
)); ?>
<div style="float: left;">
<?php echo $form->labelEx($model,'SearchString'); ?>
<?php echo $form->textField($model,'SearchString'); ?>
<?php echo $form->error($model,'SearchString'); ?>
</div>
<div class="buttons" style="float: left;">
<?php echo CHtml::ajaxSubmitButton(Yii::t('app','Search'),'search',array(
'update'=>'#searchResultContainer'
),array('id'=>'btnSearchStore', 'style'=>'margin: 20px 0 0 5px;')); ?>
</div>
<?php $this->endWidget(); ?>
</div>
<?php echo CHtml::tag('h2', array('style'=>'clear: both; padding-top: 40px;'), Yii::t('app', 'Search results')); ?>
<div id="searchResultContainer">
<p><?php echo Yii::t('app', 'No search has been executed yet'); ?></p>
</div
View _searchResult:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_searchResultItem',
'itemsTagName'=>'table',
'id'=>'#searchResultList',
)); ?>