CLinkPager widget not working correctly while listing with search option

Hi all,

I am trying to list users depending on the search criteria, but CLinkPager widget is not working correctly.  If I am searching the records with search option, first page listing is good with search criteria, but if I move on to the next page, its loosing the search criteria and not showing the results corresponding to the search option/criteria.





Without search criteria its working perfectly fine. 

Any idea?

Thank you!

can you give me you’re example? I’m interested :)

Hi,

I want to validate my users based on FullName, so my list view looks has -


<?php echo CHtml::beginForm(); ?>

 <table width="100%"  cellpadding="2" cellspacing="2">

 <tr>

 <td width="100" align="left">

 <?php echo CHtml::activeLabel($usermodel, Yii::t('Users.user','Name')); ?>

 </td>

  <td>

 <?php echo CHtml::activeTextField($usermodel, 'FullName', array('size'=>20,'maxlength'=>40));?></td>

</tr>


<tr>

 <td align="left" colspan="6">

 <?php echo CHtml::submitButton(Yii::t('Users.user','Search'),$htmlOptions=array ('class'=>'bt3dbuttons',

 'ajax' => array(

  'type'=>'POST',

   'url'=>'list',

   'update'=>'#searchResult',

   ),    

  )); ?>

  </td>

  </tr>

  </table>

  <?php echo CHtml::endForm();?>

My action looks like -




  if($_POST['user']['FullName'] != '')

 {

     $criteria->condition .= " AND FullName LIKE :FullName";

     $parameters[":FullName"] = "%".$usermodel->FullName."%";

 }


 $userdata = $usermodel->with(array("location" => array('select' => 'LocationName')))->findAll($criteria);

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

  $this->render('list', array("usermodel" => $usermodel, "userdata" => $userdata, "sort" => $sort, "pages" =>$pages));

  else

  $this->renderPartial(('list', array("usermodel" => $usermodel, "userdata" => $userdata, "sort" => $sort, "pages" =>$pages));



while navigating on first page its working fine but on second page its loosing search criteria i.e fullname.

As I can see view of pagination generated by CLinkPager is having just url to the same page/action with page number not the criterias searched for.

for example :

href url for page 2 is :

href="/testdrive/Users/user/list/page/2"

any idea?

I’m not sure if this helps you, I have a similar requirement. My client needs to easily find a participant so I provide a functionality to search by name. I have a form that submits a name and the submit button is ‘search_by_name’. The default value of $_POST[‘lastname’] is ‘Lastname’. So if the field is left alone and submit is clicked all of the entrants are returned.

If any other value a query is performed, and the $_GET[] value of ‘lastname’ is set to the current search criteria.

Pagination is working with ‘zii.widgets.grid.CGridView’, I don’t know if this works in your situation, I am too new to the framework to comment on that but maybe the code sample helps you in the right direction.


	public function actionList()

	{

		

		if ($_POST['search_by_name'] == 'submit'){ 

		    $q=$_POST['lastname'];

	  unset ($_GET);

		    $_GET['lastname'] = $_POST['lastname'];

		} else { 

		$q = $_GET['lastname'];			

		};


		if($q =='Lastname' || $q == NULL){

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

    'pagination'=>array(  

    'pageSize'=>self::PAGE_SIZE),

                 ));

		} else {

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

		'criteria'=>array(

        'condition'=>'ParticipantLastname="'.$q.'"',

        ),       

        'pagination'=>array(  

        'pageSize'=>self::PAGE_SIZE),

         ));

         };


    $this->render('list',array('dataProvider'=>$dataProvider));

	}



doodle

Had a similar issue and in my case it was the javascript on the view that was not working.

The bit that goes to the likes of:




<?php

$script = "$('.sort-buttons a, .yiiPager a').bind('click', function(){ $.post($(this).attr('href'), \$(\"#q\").serialize(), function(page) {

                $('#listpage').html(page);

        }); return false; })";

yii::app()->clientScript->registerScript('userListPagination', $script);

?>



Hope it helps.

Cass