renderPartial does not refresh

In my layout I have a gridview. Once a row in the grid is selected the page should refresh with detailed information about this row. I use renderPartial to render the view that contains the detailed information. But the view never does get refreshed.

I have been searching in the forums and on the internet. And one thing that keeps coming up is the need to set the fourth parameter in the renderPartial method to true. But even with that set, I am still running into the same issues.

I can see in FireBug that the proper output is produced, but the page is not being updated to reflect that.

I hope anybody can help me figure out what I am doing wrong.

Please help!

Here is my code:

Controller code:




public function actionIndex()

{

    ...


    $this->render('index',array(

        'dataProvider1'=>$dataProvider1,

	'dataProvider2'=>$dataProvider2,

    ));

}


public function actionList()

{

    ...


    $this->renderPartial('_list', array('dataProvider'=>$dataProvider'), false, true);

}



index view:




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

    'dataProvider'=>$dataProvider2,

    'columns'=>array(

        'name',

    ),

    'selectionChanged'=>'function(id) { selectionChanged("'.Yii::app()->baseUrl.'/index.php?r=", $.fn.yiiGridView.getSelection(id))}',

)); ?>


<?php echo $this->renderPartial('_list', array('dataProvider'=>$dataProvider1)); ?>


<script type="text/javascript">

function selectionChanged(baseUrl, id) {

    if (id != '')

    {

        $.post(baseUrl + 'session/list', {id: id[0]});

    }

}

</script>



_list view:




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

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

)); ?>



Render partial does not use layout unless the view explicity specify it by adding


$this->beginContent('//myLayout');

So this is the problem

Sorry, I misspoke. I don’t intend to use a layout in my partial view. That is not the problem. The problem is that the partial view is not being refreshed.

I am calling the index action in the controller, which renders the index view (containing a CGridView). Within the index view the _list view is rendered as partial view. That all works fine.

The problem occurs when I invoke the javascript function selectionChanged by clicking on one of the rows in the CGridView. The action list in the controller is called and the call to renderPartial is made, and under the hood _list view is updated (which is apparent when I look in FireBug at what is being returned). But the page never updates with the updated _list view information.

Alright, I found the solution to my problem.

As I mentioned, I am using the jquery post method to update my view. But I neglected to actually update the view on success.

Here is the code that worked for me:

index view:




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

    'dataProvider'=>$dataProvider2,

    'columns'=>array(

        'name',

    ),

    'selectionChanged'=>'function(id) { selectionChanged("'.Yii::app()->baseUrl.'/index.php?r=", $.fn.yiiGridView.getSelection(id))}',

)); ?>


<div id="data">

<?php echo $this->renderPartial('_list', array('dataProvider'=>$dataProvider1)); ?>

</div>


<script type="text/javascript">

function selectiongChanged(baseUrl, id) {

    if (id != '')

    {

        $.post(baseUrl + 'session/list', {id: id[0]}, function(data) {

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

        });

    }

}

</script>