Hi dear friends,
Description the problem with an example:
If there was several pages(1,2,3,4,5, . . . ) for first page change(for example 2) ajax pagination doesn’t work. but when once the page changed with post method, in next requests for changing page ajax pagination works very well. what is the reason?
action for making dataProvider:
public function actionIndex()
{
if(isset($_POST['searchItem']) && $_POST['searchItem']!==null)
Yii::app()->user->setState('searchItem',$_POST['searchItem']);
$title=Yii::app()->user->getState('searchItem');
if(isset($_POST['category']) && $_POST['category']!==null)
Yii::app()->user->setState('category',(int)$_POST['category']);
$category=Yii::app()->user->getState('category');
if(isset($_POST['subCategory']) && $_POST['subCategory']!==null)
Yii::app()->user->setState('subCategory',(int)$_POST['subCategory']);
$subCategory=Yii::app()->user->getState('subCategory');
$criteria = new CDbCriteria();
$criteria->condition="status=:Verified or status=:Active";
$criteria->params=array(':Verified'=>Advert::Verified,':Active'=>Advert::Active);
if(!empty($title)) $criteria->compare('title',$title,true);
if(!empty($category)) $criteria->compare('category_id',$category);
if(!empty($subCategory)) $criteria->compare('sub_category_id',$subCategory);
$sort = new CSort();
$sort->defaultOrder=array(
'leaf'=>CSort::SORT_DESC,
'type'=>CSort::SORT_ASC,
);
$dataProvider = new CActiveDataProvider('Advert',array(
'criteria'=>$criteria,
'sort'=>$sort,
'pagination'=>array(
'pageSize'=>10,
),
));
if((empty($dataProvider->data)))
Yii::app()->user->setFlash('Warning', '<strong>'.Yii::t('application','Item not found!').'</strong>');
if(Yii::app()->request->isAjaxRequest)
$this->renderPartial('index',array('dataProvider'=>$dataProvider));
else
$this->render('index',array('dataProvider'=>$dataProvider));
}
[b]view:
[/b]
<?php $this->widget('zii.widgets.CListView',array(
'id'=>'result',
'dataProvider' => $dataProvider,
'itemView' => '_ad',
'summaryText'=>'',
'emptyText'=>'',
'pager'=>array(
'header'=>'',
'prevPageLabel'=>'<',
'nextPageLabel'=>'>',
),
));
?>
[b]
[/b]