[EXTENSION] AlphaPager

Great news, keep it up! ;)

Greetings,

CoLT

Superb extension!!

One thing (I think bug) I have found is when using ApArrayDataProvider with ApGridView and filtering by letter, the total number of items shown in the grid summary text remains at the total of the full data set.

For example, if I have 10 items and 3 begin with C, when clicking on C I get just the 3 items shown, but the summary text in the grid shows 10 as the total.

The fix I have made is to add the following line at the end of ApArrayDataProvider::alphaFilterData()


$this->setTotalItemCount(count($this->rawData));

Great. Thank you!

Hi Yeti,

thanks for your report. I see… yes, this could happen if you have requested the totalItemCount in your app before alphaFilterData() was called. Because once calculated it will not be recalculated when the grid is created (this is up to CDataProvider).

So i think it’s a good idea to refresh the count like you have mentioned! But i’d prefer to use


$this->getTotalItemCount(true);

for this, so the internal calculateTotalItemCount() function is used.

Bug #2:

While playing around to figure out yeti’s problem i’ve found another bug that shows up when disabling pagination. The GridView will create a row for every item of the original dataset just leaving those blank which don’t fit to the selected alphapager letter.

I’ll fix these two issues and upload a new version of alphapager.

Thank you!

Best regards

Dear All,

I combine alpha pager with pageSize (http://www.yiiframework.com/forum/index.php?/topic/8994-dropdown-for-pagesize-in-cgridview). The thing is if I combined with alpha pager, the pagesize is coming back to default size which I set as 10.

For example, I am in letter "A", and there are 70 items. If the pageSize is set to 10, then only 10 items are displayed. I change the pageSize to 25, it will be correct, the 70 items are split into 3 pages, but if I am click on page 2, the pageSize back to default 10, so it becomes 7 pages.

Any help on this?

Cheers,

Daniel

Hello Daniel,

i’ve checked using AlphaPager together with the “[font=“Arial”][size=“2”]DropDown for pageSize in CGridView[/size][/font]”.

If you have defined the pagination as the subpagination of AlphaPager - something like:




ApActiveDataProvider(get_class($this), array(

			'alphapagination'=>array(

           	'pagination'=>array(

               	  'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),

		   	),

           	...

       	),

      	...

);



you stepped on a bug. The additional parameters used for configuring the subpagination are ignored if defined like this and not set for the resulting pagination object.

I’ve fixed this bug in ApPagination and will upload a new version to the extension repository within the next hour.

Hopefully this solves your issue! Otherwise just reply or send me a pm.

Best regards

Hi Yoshi,

what would be the differences when using subpagination or not? below is the return value of my model search:




 return new ApActiveDataProvider(get_class($this), array(

                'criteria'=>$criteria,

                'alphapagination'=>array(

                    'attribute'=>'name',

                    'activeCharSet'=>$activeChars

                ),

                'pagination'=>array(

                    'pageSize'=> Yii::app()->user->getState('pageSize',

                                     Yii::app()->params['defaultPageSize']),

                ),

            ));



and below is my portion of code in the controller:




...

        if (isset($_GET['pageSize'])) {

            Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);

            unset($_GET['pageSize']);

        }

        else {

            Yii::app()->user->setState('pageSize',Yii::app()->params['defaultPageSize']);

        }


...

        $merge=new CDbCriteria;

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

                $merge->order = '`name` ASC';

...



I guess I understand my problems:

  1. My dropdown pageSize error caused by this else clause



        else {

            Yii::app()->user->setState('pageSize',Yii::app()->params['defaultPageSize']);

        }



  1. Page error confusion (sorting problem maybe) caused by



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

                $merge->order = '`name` ASC';



since pager request is ajax, the order result will be different if with the one if the page is requested by non-ajax one.

It seems my problems are solved so far…

thx a lot for your help.

cheers,

Daniel

Hello Daniel,

There wouldn’t be any differences. If you define the pagination as a part of AlphaPager (the so called subpagination) for a DataProvider then AlphaPager will just pass the pagination on to the DataProvider.

To show some code:


return new ApActiveDataProvider(get_class($this), array(

'alphapagination'=>array(

	....

),

'pagination'=>array(        

	'pageSize'=> 10, 

),

));

and


return new ApActiveDataProvider(get_class($this), array(

'alphapagination'=>array(

	....

	'pagination'=>array(        

    	'pageSize'=> 10, 

	),

),

));

are the same.

These are always good news. Your first issue was definitely the ELSE-clause, because the pageSize value is only sent, when it’s changed.

Cheers

Hi Yoshi,

just wondering, how could I change the text "Go to letter", I tried "header"=>"Index" but not working.

Cheers,

Hi Daniel,

Yes, this is the correct attribute.

Example:




<?php $this->widget('ApGridView', array(

	'id'=>'myGrid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'template'=>"{summary}\n{alphapager}{pager}\n{items}",

	'alphaPager'=>array(

 			'showNumPage'=>'true',

        	'header'=>'Index: ' //  <=====Setting different header text

	),

  ....

?>



If it doesn’t work for you please post your corresponding source code, so i can take a look.

Regards

Hello,

I’ve just installed AlphaPager and tried to implement it on a module I’m working on,

here is what I have in Model of my controller


	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.

		

		Yii::import('application.extensions.alphapager.ApActiveDataProvider');


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('sef_name',$this->sef_name,true);


		//return new CActiveDataProvider(get_class($this), array(

		return new ApActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,


			'alphapagination'=>array(

				'attribute'=>'name',

			),

		));

	}

and this is my view file,


<?php $this->widget('application.extensions.alphapager.ApListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

	'template'=>"{alphapager}\n{pager}\n{items}",

)); ?>

and this is the error I’m getting:


Error 500


CActiveDataProvider does not have a method named "getAlphaPagination".

Did I miss something?

P.S. Now I just previewed my code, maybe it is trying to find the extension in module/extension directory instead of root/protected/extension directory which is where I’ve installed the extension (so I can use it on other modules)!? [size=“2”]–this doesn’t seem to be the case[/size]

Hi nix,

could it be that you have defined the $dataProvider variable inside your controller action similar to


$dataProvider=new CActiveDataProvider....

?!

You should try the following

Inside your controller action:


	public function actionYourAction()

	{

		$model=new YourModel('search');

		$model->unsetAttributes();  // clear any default values


		$this->render('YourView',array(

			'model'=>$model,

		));

	}

and inside your view:


<?php $this->widget('application.extensions.alphapager.ApListView', array(

   	'id'=>'myListView',

   	'dataProvider'=>$model->search(),

        'itemView'=>'_view',

        'template'=>"{alphapager}\n{pager}\n{items}",

   /* ... */

)); ?>

Regards

Thanks a lot yoshi, now everything works :D

You might as well want to add above code to your extension usage example, can’t be certain but I’m pretty sure I followed the installation/usage manual last night when testing the extension, though because I’m using the latest yii framework I jumped into 2nd section of the manual without reading 1st section, that might be why

Next challenge is to get rid of the page numbers under alpha blocks and put pagination to the bottom of the page, guessing that this is not going to be hard

Edit: done the pagination thing, peace of cake thanks to your template variable

Cheers

Only one issue, Using ApListView in my widget I couldn’t get showNumPage activated (kept giving the error of: Property “ApListView.showNumPage” is not defined.), as a last resort I changed the default value of false to true within ApLinkPager class which did the job and I actually prefer having this option enabled for all my lists

Hello nix,

the showNumPage property belongs to the pager itself and not to ApListView.

You can configure the alphaPager e.g. in the following way:


<?php $this->widget('application.extensions.alphapager.ApListView', array(

        'dataProvider'=>$dataProvider,

        'itemView'=>'_view',

        'template'=>"{alphapager}\n{pager}\n{items}",

        'alphaPager'=>array('showNumPage'=>true) // <==== here

)); ?>

Regards

Great extension Thank you!

I’m just begining with Yii, and i find this extension very usefull!

I was wondering if there is a simple way to not list all the entries when we are arriving on the web page:

i would like to begin with all the entries begining with an "A" for example.

Regards

Hi All:

I need to display the record number inside the view file of ‘itemView’. I mean the ranking of the record.

Just to query like this:

SET @rank=0;

SELECT @rank:=@rank+1 AS rank, fruit, amount FROM sales ORDER BY amount DESC ;

And display that rank number in the view.

How can i do this?

How can I replace the, for example alphapage=8 to alphapage=H ?

Hi,

I have a question about changing ajaxUrl. At CListView, I can change the ajaxUrl like this:


array(

   ...

   'ajaxUrl' => '/controller/action'

  ...

)

But when I want to do the same change at ApListView, the ajaxUrl won´t change - I’ve tested the request url with firebug. Have anyone an idea about this?