Issue with Pagination and AJAX Implementation

Hi there

I have developed a system that user posts comment and it gets stored in database with help of ajax.Problem is

Original pagination of CListView works but the one that is being redered by Ajax does not work

it shows empty page but when

IMPORTANT OBSERVATION

By Default when there is no AJAX Calls url in browser is

index.php?r=staff/messages/view&id=8&Messages_page=2

after AJAX CALL

index.php?r=staff/messages/create&Messages_page=2

so there is only but with URL[/b]

Flow

[b]CONTROLLER

if Save Sucess[/b]


if($model->save())

                       {

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

                              'criteria'=>array(

                                    'condition'=>'t.receiver_id = '.Yii::app()->user->id.' AND t.sender_id = '.$model->receiver_id.

                                                ' OR t.receiver_id = '.$model->receiver_id.' AND t.sender_id = '.Yii::app()->user->id,

                                    'order'=>'id DESC ',

                                ),

                            'pagination'=>array(

                                    'pageSize'=>10,

                                )));

                            //CVarDumper::dump($model,100,true);

                           //$this->render( 'view', array('dataProvider'=>$dataProvider));

                            

                            echo CJSON::encode(array(

                                'messages' => $this->renderPartial('_messages',array('dataProvider'=>$dataProvider),true),

                                'message'=>CHtml::tag('textarea',

                                        array(

                                            'style'=>'height:60px;',

                                            'class'=>'span-14',

                                            'name'=>'Messages[message]',

                                            'id'=>'Messages_message',

                                            'value'=>''),

                                        '',

                                        true)

                                ));

                        }

_messages


<?php $this->widget('zii.widgets.CListView', array(

            'dataProvider'=>$dataProvider,

            'ajaxUpdate'=> true,

            'itemView'=>'_viewonetoone',

            'summaryText'=>''

    )); ?>

_viewonetoone


<div class="span-14" >

    <div class="left span-1">

        <strong><?php echo $data->sender->name;?></strong>

    </div>

    <div  class="left span-9">

        <p>

        <?php echo  CHtml::encode($data->message); ?>

        </p>

    </div>

    <div class="left span-2" >

            <?php 

            $date = new DateTime($data->created);        

            echo CHtml::encode($date->format('jS \ M y h:i A')); ?>

    </div>

    

    <br/>

	<hr />

</div>

AjaxSubmit Button





	<div class="row buttons">

		<?php //echo CHtml::submitButton('Send',array('class'=>'submit')); 

                    echo CHtml::ajaxSubmitButton('Send',CController::createUrl('/staff/messages/create'),

                            array(

                                'dataType'=>'json',

                                'success'=>'function(data){

                                    $("#ajaxListView").html(data.messages);

                                    $("#newMessage").html(data.message);

                                    }',

                                //'update' => '#ajaxListView,#Messages_message',

                                'type' => 'POST'

                                ));

                ?>

	</div>



Note

Data gets updated the only issue is with the pagination

Instead of rendering the partial view in your ajax response, can you use CListView’s ajax update method to update the list?




        <div class="row buttons">

                <?php

                    echo CHtml::ajaxSubmitButton('Send',CController::createUrl('/staff/messages/create'),

                            array(

                                'dataType'=>'json',

                                'success'=>'function(data){

                                    $.fn.yiiListView.update("#ajaxListView");

                                    $("#newMessage").html(data.message);

                                    }',

                                'type' => 'POST'

                                ));

                ?>

        </div>