Generic ajax pagination

Hello,

I’m trying to use CLinkPager to load a set of data without using CListView and if I’m right, at this time it is not possible to use it with ajax as you would do with ajaxLink for example. I was convinced that this feature was “built-in” cause it is for CListView and then I hoped there were some parameters for CLinkPager like “useAjax”=>true but didn’t found anything similar as I wrote…

so, my question is, which is the best way to use the CLinkPager for ajax pagination? What I’d like to achieve is just call an action with an ajax request and pass to the action the page number to load and then have back the results of the ajax callback… ::)

thanks.

bye,

Giovanni.

Ciao Giovanni!

In this case you have to extend CLinkPager and override the function createPageButton




Class AjaxLinkPager extends CLinkPager

{

        /**

         * Creates a page button.

         * You may override this method to customize the page buttons.

         * @param string the text label for the button

         * @param integer the page number

         * @param string the CSS class for the page button. This could be 'page', 'first', 'last', 'next' or 'previous'.

         * @param boolean whether this page button is visible

         * @param boolean whether this page button is selected

         * @return string the generated button

         */

        protected function createPageButton($label,$page,$class,$hidden,$selected)

        {

                if($hidden || $selected)

                        $class.=' '.($hidden ? self::CSS_HIDDEN_PAGE : self::CSS_SELECTED_PAGE);

                return '<li class="'.$class.'">'.CHtml::ajaxLink($label,$this->createPageUrl($page)).'</li>';

        }





}



Hi,

thanks for your reply! I think that your suggestion does more or less what I’ve achieved but in a more elegant way ;)

But I think that then I’d still have the problem that once I click a button I won’t get the selected item updated and (a bit more boring ;)) if I click the “next” button I won’t get the url of the button itself updated so clicking it again won’t do anything ::)

A “quick-n-dirty” solution would be to reload also the CLinkPager with the new code obtained from the ajax callback but I don’t like this option that much; how did you managed this? Thanks.

bye,

Giovanni.