Yii Framework Forum: [EXTENSION] AlphaPager - Yii Framework Forum

Jump to content

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] AlphaPager Simple alphanumeric pager Rate Topic: ***** 2 Votes

#21 User is offline   CoLT 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 246
  • Joined: 22-November 09

Posted 16 May 2010 - 04:53 AM

I'm glad to inform that lower case with forceCaseInsensitive now works fine! :)

Would be nice now to integrate it with CListView! :)

CoLT
0

#22 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 16 May 2010 - 06:03 PM

Hey,

1. Gii
Well, i don't think there is any need to provide a template for gii implementing AlphaPager. Everyone can create a custom template (as explained here) and add the code for AlphaPager nearly the same as it would be done when adding it to an existing controller and view file.

2. Adding AlphaPager to CListView
This needs a little bit more to be done. Therefore i've created two files derived from CActiveDataProvider and CListView which adds AlphaPager to the ListView widget.

Here is an example for using this with the blog demo app. The posts are selected by the first letter of their title (well it's just an example :D):

In PostController.php
    public function actionIndex()
    {
        $criteria=new CDbCriteria(array(
            'condition'=>'status='.Post::STATUS_PUBLISHED,
            'order'=>'update_time DESC',
            'with'=>'commentCount',
        ));
        if(isset($_GET['tag']))
            $criteria->addSearchCondition('tags',$_GET['tag']);

        // This is just for disabling buttons which have no results
        $acCriteria=new CDbCriteria;
        $acCriteria->select='DISTINCT(SUBSTR(`title`,1,1)) AS `title`'; 
        $chars = Post::model()->findAll($acCriteria);
        foreach($chars as $char)
            $activeChars[]=$char->title;

        $dataProvider=new ApActiveDataProvider('Post', array(
            'alphapagination'=>array(
                'attribute'=>'title',
                'activeCharSet'=>$activeChars,
            ),
            'pagination'=>array(
                'pageSize'=>Yii::app()->params['postsPerPage'],
            ),
            'criteria'=>$criteria,
        ));

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


and in posts index-view (views/post/index.php):
<?php $this->widget('ApListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'template'=>"{items}\n{pager}\n{alphapager}",
)); ?>


You'll need ApActiveDataProvider.php and ApListView.php which are attached to this post.

Regards

Attached File(s)


0

#23 User is offline   CoLT 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 246
  • Joined: 22-November 09

Posted 17 May 2010 - 10:49 AM

Hello,

Nice! A bit dirty but working implementation!

:) But following questions goes here:

1. After implementing AlphaPager with CListView - default Filtered values, Records count is no longer showed.

Using in Index View:
<?php $this->widget('ApListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'template'=>"{items}\n{pager}\n{alphapager}",
    'sortableAttributes'=>array(
        'ClLName'=>'Last name',
        'ClFName'=>'First name',
),
)); ?>


2. How to place AlphaPager in the top of Index View?

CoLT
0

#24 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 17 May 2010 - 01:52 PM

View PostCoLT, on 17 May 2010 - 10:49 AM, said:

Nice! A bit dirty but working implementation!


Yes, quick and dirty! :D But hey - it's just an example.

View PostCoLT, on 17 May 2010 - 10:49 AM, said:

1. After implementing AlphaPager with CListView - default Filtered values, Records count is no longer showed.
2. How to place AlphaPager in the top of Index View?


Please have a look at CListViews docu for those things. E.g. to make record count visible you'll need to add {summary} to the template property and to make the pager appear at the head you have to place their tags before {items}.

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


Regards
0

#25 User is offline   CoLT 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 246
  • Joined: 22-November 09

Posted 17 May 2010 - 05:33 PM

Super! Thanks!

This extension really made my day! :D

AlphaPager is a must have extension ;D

Best regards,
CoLT
0

#26 User is offline   CoLT 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 246
  • Joined: 22-November 09

Posted 18 May 2010 - 05:41 AM

Somehow I don't see 'sortableAttributes' with 'template'=>"{summary}\n{alphapager}\n{pager}\n{items}\n{pager}",

Where is the problem?:)

CoLT
0

#27 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 18 May 2010 - 06:37 AM

View PostCoLT, on 18 May 2010 - 05:41 AM, said:

Somehow I don't see 'sortableAttributes' with 'template'=>"{summary}\n{alphapager}\n{pager}\n{items}\n{pager}",

Where is the problem?:)


Hi,

add {sorter} to your template and set sortableAttributes:

<?php $this->widget('ApListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'template'=>"{sorter}\n{summary}\n{alphapager}\n{pager}\n{items}",
    'sortableAttributes'=>array(
          'title',
          'create_time'=>'Post Time',
    ),
)); ?>


Regards
0

#28 User is offline   CoLT 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 246
  • Joined: 22-November 09

Posted 18 May 2010 - 09:15 AM

View Postyoshi, on 18 May 2010 - 06:37 AM, said:

Hi,

add {sorter} to your template and set sortableAttributes:

<?php $this->widget('ApListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'template'=>"{sorter}\n{summary}\n{alphapager}\n{pager}\n{items}",
    'sortableAttributes'=>array(
          'title',
          'create_time'=>'Post Time',
    ),
)); ?>


Regards


Thanks.. How did I missed that :D guess need to have a nap :D

Best regards,
CoLT
0

#29 User is offline   aztech 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 12-December 08
  • Location:Poland

Posted 27 May 2010 - 05:03 PM

Small tip to all who are "fighting" with i18n. Just add collation to your select and all letters will be highlighted correctly in alphapager
$c->select='DISTINCT(substr(`lastname`,1,1)) COLLATE utf8_polish_ci AS `lastname` ';

I'm not complete idiot... some parts are missing!
0

#30 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,735
  • Joined: 17-January 09
  • Location:Russia

Posted 01 July 2010 - 06:17 AM

Thanks for this useful extension with good enough documentation not to check its source code when you need something.

The only drawback is that its classes are not prefixed with E like EAlphaLinkPager that can possibly lead to naming conflicts.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#31 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 01 July 2010 - 11:44 AM

Hi,

View Postsamdark, on 01 July 2010 - 06:17 AM, said:

Thanks for this useful extension with good enough documentation not to check its source code when you need something.

Thank you!

View Postsamdark, on 01 July 2010 - 06:17 AM, said:

The only drawback is that its classes are not prefixed with E like EAlphaLinkPager that can possibly lead to naming conflicts.

Yes, that's unfortunately right. But changing the classnames now or in a next version is bad for everyone who is already using AlphaPager...

Best regards
0

#32 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,735
  • Joined: 17-January 09
  • Location:Russia

Posted 01 July 2010 - 02:40 PM

Well, since it's not placed under version control and can't be used via externals, developers will not have unexpected problems with it. I think mentioning it in changelog or upgrade.txt will be enough.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#33 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 01 July 2010 - 03:11 PM

View Postsamdark, on 01 July 2010 - 02:40 PM, said:

Well, since it's not placed under version control and can't be used via externals, developers will not have unexpected problems with it. I think mentioning it in changelog or upgrade.txt will be enough.


That's right, there wouldn't be unexpected problems. It's in fact pretty simple, because you would only need to do a search/replace on filepath for corresponding import or widget function calls, but i think i for myself wouldn't normally expect such a change when i'm updating an extension from someone else and to be honest this would piss me off :rolleyes:

In general i agree that it would be better to prefix the classnames - my fault - and i'll think about how to achieve this in a gently way. Cause i don't wanna code Microsoft-style with keeping all failures and problems just for backward compatibility :D

Regards
0

#34 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 02 July 2010 - 02:13 AM

@samdark:
There are more extensions "breaking the law" already. How about having some required checkboxes on the "Create new extension" page, that all need to be checked? Something like:

Please read and "sign" these conditions:

[ ] My extension doesn't break any existing licenses...
[ ] The classes in my extension don't use the "C" prefix, which is reserved for framework files
...

So no one should miss these rules anymore.

EDIT: And sorry for OT. Further discussion should be put into a new thread.

This post has been edited by Mike: 02 July 2010 - 02:14 AM

0

#35 User is offline   larry 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 01-April 09
  • Location:State College, PA, US

Posted 16 July 2010 - 12:17 PM

I need to get this working with GridView and was thinking about creating an ApGridView class that extends CGridView. Before I did that, I thought I'd check to see if you (yoshi) had any plans on doing so already. Thanks for everything you've already done!
Writer/Web Developer/Programmer/Instructor
LarryUllman.com
Author of "The Yii Book"
0

#36 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 19 July 2010 - 11:08 AM

Hi larry,

a few posts up is an (quick 'n dirty) example i've done to implement AlphaPager into a GridView by extending the ListView and the DataProvider.
But at the moment i've no further plans on making a clean extension of CGridView.

So you're really welcome to do so! :)

Best regards
0

#37 User is offline   larry 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 01-April 09
  • Location:State College, PA, US

Posted 20 July 2010 - 10:41 PM

Hello Yoshi,

Thanks for your reply and, again, for your work. I may be the daftest person around, though, as I don't see where you've posted a quick 'n dirty example to implement AlphaPager into GridView. I see your code for extending the ListView and the DataProvider (ApListView and ApDataProvider, respectively), but don't see any reference to GridView. I suspect I'm missing something obvious. Are you just then editing the _view.php template so that it works like a table row?

I've muddled about trying to make an ApGridView class that extends CGridView, based upon what you did with CListView, but I get an error about CPagination not having a getCharSet method. I've figured out that this is happening because $this->pages (in AlphaLinkPager) ends up being a CPagination object, not an AlphaPagination one. I'm currently trying to hunt down why that's happening.

Any insights into what I'm missing would be much appreciated. Thanks!
Writer/Web Developer/Programmer/Instructor
LarryUllman.com
Author of "The Yii Book"
0

#38 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 21 July 2010 - 06:07 AM

Hi larry,

no, i'm the jerk :D Of course you're right the example is just for extending the ListView.

But i tried to directly port it to a GridView without having any problems.

Here is what i did:
  • Extending CGridView (exactly the same as with CListView, just change the classname etc.). The file is attached to this comment.
  • Change the DataProvider inside your models search() function (using the ApDataProvider from previous post). This way there is no need to touch the controller.
    E.g.:
    $dataprovider = new ApActiveDataProvider('MyModel', array(
                    'alphapagination'=>array(
                        'attribute'=>'Name',
                        //'activeCharSet'=>$activeChars,
                    ),
                    'pagination'=>array(
                        'pageSize'=>10,
                    ),
                    // ...
            ));
  • Change the GridView inside your view file:
    $this->widget('ApGridView', array(
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'template'=>"{alphapager}\n{pager}\n{items}",
    // ...
    ));
    

That's it and it's working like a charm over here :)

Hopefully this helps you otherwise just let me know!

Regards

Attached File(s)


0

#39 User is offline   larry 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 01-April 09
  • Location:State College, PA, US

Posted 21 July 2010 - 06:41 PM

No, absolutely not a jerk! Thank you very much for the help and I'm glad I wasn't missing something obvious. Yes, no problem getting that working.

One thing I discovered is that it's best to add a defaultScope() to the model adding an order that uses the same column as the AlphaPager. That way results are restricted by letter (thanks to the AlphaPager) but also in alphabetical order, which I think is more logical. You (yoshi) know this, of course, but others might appreciate the extra info.

A thousand thanks!
Writer/Web Developer/Programmer/Instructor
LarryUllman.com
Author of "The Yii Book"
0

#40 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 14 November 2010 - 02:46 PM

NEW VERSION 1.3 RELEASED
--------------------------------------------------------------
With everything needed to include AlphaPager with Grid-/ListView (including AJAX support). ActiveDataProvider, ArrayDataProvider and extended versions of GridView and ListView.
These are reworked versions of those already published within this topic.

Take care when updating from a previous version of Ap, because as mentioned by samdark i've updated the file- and classnames to avoid potential naming-conflicts. See README.txt from the package!

The documentation was also redesigned and a demopage will follow.

Best regards
2

Share this topic:


  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users