ClinkPager & Ajax

hi all ,

i have a question about implementing ‘ClinkPager’ with ajax.

i have a page where i want to display users comments and i’m doing it with CLinkPager.

i extended CLinkPager because i wanted to change the links to be ajax Links with additional params i wanted.

anyway ,

my problem is that i want the ClinkPager to update a DIV (that works) but the ClinkPager Doesnt included inside that div.

so …

i need to change the CLinkPager’s links (just the ones for next and previous) AFTER anyone of the page numbers clicked …

is This possible ??

The Extended CLinkPager’s code is :




class CommentsPager extends CLinkPager{


    public $videoID;


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

        {

            $perPage = $this->getPageSize();

            $startIndex = $page*$perPage + 1;

            $beforeSendFunc = <<<EOF

            function(){

//                $('body').undelegate('#button-PrevTop', 'click');//undelegete the 'click' event ( Yii Ajax BUG)

                $(".page").removeClass("selected");//remove selected from current

                $(".button-page$page").parent(".page").addClass("selected");

                $('#div-Comments').html('').addClass('CommentLoader');


                $('body').undelegate('.previous a','click');

                $('body').undelegate('.next a','click');


                }

EOF;

            $SuccessFunc = <<<EOF

            function success(data, textStatus, jqXHR)

            {

                $('#div-Comments').removeClass('CommentLoader').html(data);

                

            }

EOF;

            $errorFunc = <<<EOF

            error(jqXHR, textStatus, errorThrown)

            {

                $('#div-Comments').removeClass('CommentLoader').html(textStatus);

            }

EOF;

            

                if($hidden || $selected)

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

                return '<li class="'.$class.'">'.CHtml::ajaxLink($label,

                                                                 Yii::app()->controller->createUrl('GetNextComments',

                                 array(

                                 'startIndex'=>$startIndex,

                                 'maxResults'=>$perPage,

                                 'videoID'=>$this->videoID,

                                 'page'=>$page,

                         )

                 )

              ,array('update'=>'#div-Comments',

                     'beforeSend'=>$beforeSendFunc,

                     'success'=>$SuccessFunc

                     )

               ,array('class'=>'button-page'.$page)).'</li>';

        }





}

anyone has an idea how i should solve this ??

I just included some jquery to the bottom of my view to override the click function of each link.

For the widget I added an ID, eg


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

				'pages' => $pages,

				'header'=>'<center>',

				'footer'=>'</center>',

				'id'=>'link_pager'

				)) ?>

Then I added the following javascript to my view


<script>

$(document).ready(function(){

	$('#link_pager a').each(function(){

			$(this).click(function(ev){

				ev.preventDefault();

				$.get(this.href,{ajax:true},function(html){

						$('#resultHolder').html(html);

					});

				});

		});

	});

</script>

I then used the ajax variable to determine what I need to output, using renderPartial if the ajax get variable is present.

here is the Ajax function, on click on pagination link, you can hit the url by this way…:)




$("ul#clinkPageId li a").on('click',function (e){

        e.preventDefault();

        loadlistData($(this).attr('href'));

    }); 



and here the ajax way to render data




function loadlistData(url)

 {//show loader.

    $("#resultContainer").html(loader);

    var search = $('#search').val();

    var url = url || '<?php echo Yii::app()->createUrl('admin/controller/action')?>';

    $.ajax({type:"POST", url:url,data:{'search':search},success:function(data){

           $("#resultContainer").html(data);

           $('#subcategoryMsg').html('<?php echo  (Yii::app()->user->hasFlash('success')) ? Yii::app()->user->getFlash('success') : ''?>');

    }}); 

 }



here is controller action define




public function actionSubCategoryList()

        {

            

                       

            $criteria->compare('colume',1);

            $criteria->addCondition('conlunm2=0');

            $criteria->order = 'column';

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

                                'criteria'=>$criteria,

                                'pagination'=>array(

                                'pageSize'=>Yii::app()->params->pageSize,

                    )

            )); 

            $this->renderPartial('_subcategorylist',array(

                    'dataProvider'=>$dataProvider,

            )); 

        }