Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

ajax pagination

This class allows ajax request content to be easily paginated with desired visual effect.

<?php
/**
        @name               ajaxpager.class.php
        @desc               allows ajax pagination.
                            $pager:pager object created using sfPropelPager
                            $url:URL of desired action.(mostly current ajax action)
                            $divId:id of div to be updated after pagination
                            $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself)
                            $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc.
        @author             Ahmet ERTEK, erteka@gmail.com
        @copyright          DVS Bilisim, www.dvs-tr.com
        @version            1.0.0
 
*/
class ajaxpager
{
    private $pager;
    private $divId;
    private $url;
    private $params;
    private $appear_effect;
 
    /**
        @name               ajaxpager.class.php
        @desc               allows ajax pagination.
                            $pager:pager object created using sfPropelPager
                            $url:URL of desired action.(mostly current ajax action)
                            $divId:id of div to be updated after pagination
                            $params:extra parameters to send with pager (but not implemented yet.you can implement it by yourself)
                            $appear_effect:visual effect on completing the request.(default is 'Appear').You can use also 'Grow' or 'SlideDown' etc.
        @author             Ahmet ERTEK, erteka@gmail.com
        @copyright          DVS Bilisim, www.dvs-tr.com
        @version            1.0.0
 
*/
    public function ajaxpager($pager,$url,$divId,$params=null,$appear_effect='Appear')
    {
        $this->pager=$pager;
        $this->divId=$divId;
        $this->url=$url;
        $this->params=$params;
        $this->appear_effect=$appear_effect;
 
    }
/**
        @name               ajaxpager.class.php
        @desc               prints pagination.
        @author             Ahmet ERTEK, erteka@gmail.com
        @copyright          DVS Bilisim, www.dvs-tr.com
        @version            1.0.0
 
*/
    public function printPager()
    {
        $pager=$this->pager;
        $url=$this->url;
        $divId=$this->divId;
        $appear_effect=$this->appear_effect;
 
        if ($pager->haveToPaginate())
        {
            echo link_to_remote('«', array(
            'update' => $divId,
            'url'    => $url.'?page='.$pager->getFirstPage(),
            'complete'=>visual_effect($appear_effect, $divId),
            'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'",
            ), array('class'=>'contentLink'));
 
            link_to_remote('<', array(
            'update' => $divId,
            'url'    => $url.'?page='.$pager->getPreviousPage(),
            'complete'=>visual_effect($appear_effect, $divId),
            'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'",
            ), array('class'=>'contentLink'));
 
            $links = $pager->getLinks();
            foreach ($links as $page)
            {
                echo($page == $pager->getPage()) ? $page : link_to_remote($page, array(
                'update' => $divId,
                'url'    => $url.'?page='.$page,
                'complete'=>visual_effect($appear_effect,$divId),
                'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'",
                ), array('class'=>'contentLink'));
 
                if ($page != $pager->getCurrentMaxLink()){ echo "-"; }
            }
 
            echo link_to_remote('»', array(
            'update' => $divId,
            'url'    => $url.'?page='.$pager->getNextPage(),
            'complete'=>visual_effect($appear_effect, $divId),
            'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'",
            ), array('class'=>'contentLink'));
 
            link_to_remote('>', array(
            'update' => $divId,
            'url'    => $url.'?page='.$pager->getLastPage(),
            'complete'=>visual_effect($appear_effect, $divId),
            'loading'=>"$('$divId').innerHTML='<img src=/images/indicator.gif border=0>'",
            ), array('class'=>'contentLink'));
        }
    }
}
 
?>

Usage:

<?php
$ajax_pager=new ajaxpager($pager,'myDivId','account/pictures?id='.$accountId,null,'SlideDown');
$ajax_pager->printPager();
?>
by ahmet ertek on 2007-01-23, tagged pager  pagination 

Comments on this snippet

gravatar icon
#1 Francois Zaninotto on 2007-01-23 at 08:48

What's the benefit over the sfPagerNavigationPlugin?

http://www.symfony-project.com/trac/wiki/sfPagerNavigationPlugin

gravatar icon
#2 ahmet ertek on 2007-01-24 at 12:57

sfPagerNavigationPlugin is suitable just for symfony 1.0 and later isnt it? But this class can be added to any version of symfony.In usage of course it doesnt have a benefit over sfPagerNavigationPlugin. But it may be improved later.

You need to create an account or log in to post a comment or rate this snippet.