Reputation: 1232
I tried the code from http://www.yiiframework.com/forum/index.php/topic/16797-data-picker/ to implement a data picker. Everything is working fine except for the search function of the CGridView rendered in CJuiDialog. Furthermore, there is no JavaScript error shown on the console. All codes are in _form.php (originally generated by Yii CRUD generator). By the way, I already tried the solution in Yii CGridView rendered inside CJuiDialog won't be filtered or ordered and still didn't solve my problem.
<div class="row">
<?php echo $form->labelEx($model,'company_id'); ?>
<?php echo $form->hiddenField($model,'company_id'); ?>
<input type="text" name="company_name" id="company_name" readonly value="" />
<?php echo CHtml::Button('x', array('name' => 'del_co', 'id' => 'del_co', 'onclick' => '$("#company_name").val("");$("#Customer_company_id").val("")')) ?>
<?php echo CHtml::Button('Get Company',
array('onclick'=>'$("#co_dialog").dialog("open"); return false;',
)) ?>
<?php echo $form->error($model,'company_id'); ?>
</div>
And at the end of the form div I added the part for CJuiDialog with CGridView inside:
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',
array(
'id'=>'co_dialog',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'List Company',
'width'=>'auto',
'autoOpen'=>false,
),
));
$this->widget('zii.widgets.grid.CGridView',
array(
'id'=>'co-select-grid',
'dataProvider'=>$model_co->search(),
'filter'=>$model_co,
'columns'=>array(
'company_name',
array(
'header'=>'',
'type'=>'raw',
'value'=>'CHtml::Button("+", array(
"name" => "send_co",
"id" => "send_co",
"onClick" => "$(\"#co_dialog\").dialog(\"close\"); $(\"#company_name\").val(\"$data->company_name\"); $(\"#Customer_company_id\").val(\"$data->id\");"
))',
),
),
));
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
Upvotes: 0
Views: 1305
Reputation: 1232
Finally figured out that I need the following code in the related controller. After instantiating the Company class with search scenario
$model_co = new Company('search');
Need to add these,
$model_co->unsetAttributes();
if(isset($_GET['Company']))
$model_co->attributes=$_GET['Company'];
After which the filtering would work as expected.
Upvotes: 1