Hi
i use an CActiveDataProvider and object of another model on my action. in dataprovider i use cache, but in my gridview of another loaded model cant update via ajax at once. this is the code:
controller action :
public function actionIndex()
{
// for contact list
$model=new Contact('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Contact']))
$model->attributes=$_GET['Contact'];
$dependecy = new CDbCacheDependency('SELECT MAX(create_time) FROM {{feed}}');
$duration = 1000;
$criteria = new CDbCriteria();
$criteria->limit = 10;
$criteria->order = 'create_time DESC';
$dataProvider=new CActiveDataProvider(Feed::model()->cache($duration, $dependecy, 2), array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>10,
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model,
));
}
part of view : (its not important i think because it work seperatley fine)
...
<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
$('#contact-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<div class="widget">
<div class="widget-header"> <i class="fa fa-phone-square"></i>
<h3>دفترچه تلفن</h3>
</div>
<div class="widget-content">
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row">
<?php //echo $form->label($model,'name'); ?>
<?php echo $form->textField($model,'name',array(
'size'=>60,
'maxlength'=>127,
'class'=>'input-block-level',
)); ?>
</div>
<?php $this->endWidget(); ?>
</div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'contact-grid',
'dataProvider'=>$model->search(),
'pager'=>array(
'class'=>'CLinkPager',
),
'columns'=>array(
//'id',
array(
'htmlOptions'=>array(
'style'=>'width: 5%;min-width: 20px;',
),
'class'=>'CButtonColumn',
'buttons'=>array(
'fav' => array(
'label'=>'مهم', // text label of the button
'url'=>'Yii::app()->createUrl("contact/fav", array(
"id"=>$data->id,
))',
'click'=>"function(){
$.fn.yiiGridView.update('contact-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$.fn.yiiGridView.update('contact-grid');
}
})
return false;
}
",
'imageUrl'=>Yii::app()->baseUrl.'/images/site/star-gray.png', // image URL of the button. If not set or false, a text link is used
'options'=>array(), // HTML options for the button tag
//'click'=>'...', // a JS function to be invoked when the button is clicked
'visible'=>'$data->fav == 0', // a PHP expression for determining whether the button is visible
),
'unfav' => array(
'label'=>'مهم نیست', // text label of the button
'url'=>'Yii::app()->createUrl("contact/unfav", array(
"id"=>$data->id,
))',
'click'=>"function(){
$.fn.yiiGridView.update('contact-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$.fn.yiiGridView.update('contact-grid');
}
})
return false;
}
",
'imageUrl'=>Yii::app()->baseUrl.'/images/site/star-gold.png', // image URL of the button. If not set or false, a text link is used
'options'=>array(), // HTML options for the button tag
//'click'=>'...', // a JS function to be invoked when the button is clicked
'visible'=>'$data->fav == 1', // a PHP expression for determining whether the button is visible
),
),
'template'=>'{fav}{unfav}',
),
'name',
array(
'name'=>'tel',
'type'=>'html',
'value'=>'"<pre class=description-wrapper>".$data->tel."</pre>"',
),
array(
'name'=>'cel',
'type'=>'html',
'value'=>'"<pre class=description-wrapper>".$data->cel."</pre>"',
),
array(
'name'=>'fax',
'type'=>'html',
'value'=>'"<pre class=description-wrapper>".$data->fax."</pre>"',
),
),
'template'=>'{items}{pager}',
));
?>
</div>
</div>
</div>
...
<!--<div class="widget-content">
<ul class="news-items">
<?php /*$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'template'=>'{items}',
)); */?>
</ul>
</div>-->
...