Seems to be a bug while load CListView using ajax

I’ve got some problems with ClistView (which loaded through ajax). And I suppouse it is kinda bug.

Here is my example:

controller actionConvList:


public function loadconv2($searchstr) //it creates dataProvider with fillter using value of $searchstr

	{

		$searchstr="%".$searchstr."%"; //if $searchstr is empty it will get all rows from DB

		$dataProvider = new CActiveDataProvider('Conv', array(

                        'criteria' => array(

							'with'=>array(

									'users'=>array(

											'condition'=>'user_id=:userId',

											'order'=>'lastchange DESC',

											'together'=>true,

											'params'=>array(':userId'=>Yii::App()->user->id),

									),

							),


							'condition'=>'conv_name like :srch',

							'params'=>array(':srch'=>$searchstr),

						),

                         'pagination' => array(

                                'pageSize' => '1',

                        ) 

                ));

		return $dataProvider;

	}


	public function actionConvList() //at the biginning it renders convlist view but if request is ajax it uses renderPartial

	{

		$sstr=$_POST['search_input_field']; //

		$dataProviderConv=$this->loadconv2($sstr);

		if (Yii::app()->request->isAjaxRequest){

			$this->renderPartial('//conv/convlist', array(

                'dataProviderConv'=>$dataProviderConv,

				'sstr'=>$sstr,

			));

		}else {

			$this->render('//conv/convlist', array(

					'dataProviderConv'=>$dataProviderConv,

					'sstr'=>$sstr,

				));

		}		

	}

view convlist (if request isAjaxRequest - render just <div id=data> otherwise render <input> + <div id=data>):




//at the begining request isn't ajax, so controller render this view (<input ... > and <div id=data>...</div>)

//if request isAjaxRequest  controller use renderPartial and show only new <div> in this view, and this new div replace old one

<?php if (Yii::app()->request->isAjaxRequest): ?>

<div id="data" style='clear:both'>

<?php 

$this->renderPartial('//conv/_ajaxContent', array(

	'dataProviderConv1'=>$dataProviderConv,

	)); 

?>

</div>

<?php else: ?>

<?php 

		echo CHtml::textField(

			'search_input_field',

			'',

			array(

				'id'=>'search_input',

				'class'=>"e",

				 'onkeyup'=>CHtml::ajax(

				array(

						'type'=>'POST',

						'url'=> Yii::app()->createUrl('//conv/convlist'),

						'update'=>'#data',

						'data'=>'js:jQuery(this).serialize()'

					)

				), 

				

			)

		);

		?>


		

<div id="data" style='clear:both;'>

<?php 

 $this->renderPartial('//conv/_ajaxContent', array(

	'dataProviderConv1'=>$dataProviderConv,

	));  

?>

</div>


<?php endif; ?>




view _ajaxContent




<?php 

 	$this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProviderConv1,

	'itemView'=>'//conv/_convview',

	'enableSorting'=>true,

	'ajaxUpdate' => true,

	'template'=>"{items}\n{pager}", //this remove: Displaying #... of ... result

	'cssFile'=> Yii::app()->theme->baseUrl.'/style.css',

	));  

?>



_convview has smth like this:


<?php echo CHtml::encode($data->id).'<br>'; ?>



  1. I type in browser this link: .../conv/convlist -> there are <input> and ClistView (with pagination) on my page. CListView is not filtered yet (for example it has 10 pages)

  2. I’m typing some words in <input> … ajax takes place and it loads new ClistView

  3. CListView (with ajax pagination) apears … and this CListView is filtered (for example, now it has 3 pages)

  4. in CListView I’m trying to swith between pages… but after I click on pagination smth happens and there is no filtering anymore (I mean after clicking on page 2… CListView has all 10 page as it had at the begining)

So…I think it’s kinda bug. Or maybe I’m doing smth. wrong?

Thanks!

When you switch between pages after filtering (step 3)

The method actionConvList() is called and at that time $_POST[‘search_input_field’] is empty (not set)… that’s why you get “again” all the data.

Thank you!

Could you tell me how could I add parameter(search_input_field) to pagination in CListView (to avoid described situation) ?

Just change the search input from POST to GET

‘type’=>‘POST’ to


'type'=>'GET'

and

$sstr=$_POST[‘search_input_field’]; to


$sstr=$_GET['search_input_field'];

Thank you very much!