The top gridview displayes the parent model’s records.
The bottom gridview displayes the child records - obtained via the dataprovider(targeting the child model and using the child model’s many-many relation). This part works fine.
If the user clicks a record in the parent gridview, it activates the ParentRecordClick javascript function, which:
- 
gets the new parentRecordId in the top gridview (to be used as condition by the dataprovider) and;
 
- 
updates the bottom gridview.
 
So I need the dataprovider to be refreshed before the bottom gridview is updated - but it does not happen.
<?php
$this->widget('zii.widgets.grid.CGridView', array( 
'id'=>'parent-grid', 
'dataProvider'=>$parent_model->search(), 
'filter'=>$parent_model, 
'columns'=>array(
	'role_id',
	'role_desc',
	'system_record',
	array(
		'class'=>'CButtonColumn',
	),
),
'selectionChanged'=>'ParentRecordClick',
)); 
$parentRecordId=1; // This must still be changed to get the Id of the first record in the parent gridview
?>
<?php
$dataProvider = new CActiveDataProvider('Permission'/* related model */, array( 
	'criteria'=>array( 
		'with'=>array('roleRelation' /* many-many relation-name in related model */ =>array( 
			'together'=>'true', 
			'alias'=>'rolePermissions' /* name for the combined file*/)),
			'condition'=>"rolePermissions.role_id=$parentRecordId",
	), 
));
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'permissions-grid',
	'dataProvider'=>$dataProvider,
	'columns'=>array(
		'permission_id',
		'authcontroller_id',
		'authaction_id',
		'system_record',
		array(
			'class'=>'CButtonColumn',
			'viewButtonUrl' => 'array("permission/view", "id"=>$data->permission_id)',
			'updateButtonUrl' => 'array("permission/update", "id"=>$data->permission_id)', 
			'deleteButtonUrl' => 'array("permission/delete", "id"=>$data->permission_id)',
		),
	),
));	
?>
<script type="text/javascript">
function ParentRecordClick(target_id) { 
	$parentRecordId=$.fn.yiiGridView.getSelection(target_id);
	$.fn.yiiGridView.update('permissions-grid');
}
</script>