Hi.
I managed to let an user open an Ajax modal box to select a foreign key value, displaying the complete CGridView.
The CGridView is inside a view from the object being selected.
Unfortunately, when i click a field title (for example name) to order the records, the page changes to
http://localhost/app/mybeautifulapp/myObject/ajaxlist?id_otherobject=10&myObject_sort=name
This is my code:
Button to display the Ajax dialog (inside a view)
<?php echo CHtml::link('Open list', Yii::app()->createUrl('myobject/AjaxList'),
array('class' => 'openDlg divDialog', 'onClick'=> "UNINTERESTING_FUNCTION()")); ?>
CJuiDialog (inside the same view)
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array('id'=>'divDialog',
'options'=>array( 'title'=>'My List', 'autoOpen'=>false, 'modal'=>true, 'width'=>600)));
?>
<div class="divForForm" id="myResults"></div>
<?php
$this->endWidget();
?>
AjaxList (view from myObject)
<?php
Yii::import('zii.widgets.grid.CGridView');
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'myObject-grid',
'dataProvider'=>$dataProvider, // obviously this comes from the controller
'columns'=>array(
/*
array(
'class'=>'CButtonColumn',
),
*/
array(
'name' => 'mainField',
'type' => 'raw',
'value' => 'CHtml::link($data->mainField, "JAVASCRIPT_FUNCTION_TO_SELECT_FIELD")',
'htmlOptions' => array('class'=>'chooseField',),
),
'name',
'address',
),
)); ?>