Note that there are some explanatory texts on larger screens.

plurals
  1. POyii : how to ajax update the cgridview
    text
    copied!<p>Q : How to ajax update the CgridVeiw?</p> <p>Status : I've done with cookie. but there are a problem. it is when the page upload, the date are always show in from-date and to-date text box. and When reload the page, it doesn't clear out.</p> <p>This is my view</p> <pre><code>&lt;?php $form=$this-&gt;beginWidget('CActiveForm', array( 'id'=&gt;'page-form', 'enableAjaxValidation'=&gt;true, )); ?&gt; &lt;div style="margin-top:30px;"&gt; &lt;b&gt;From :&lt;/b&gt; &lt;?php $this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array( 'name'=&gt;'from_date', // name of post parameter //'value'=&gt;Yii::app()-&gt;request-&gt;cookies['from_date']-&gt;value, // value comes from cookie after submittion 'options'=&gt;array( 'showAnim'=&gt;'fold', 'dateFormat'=&gt;'yy-mm-dd', ), 'htmlOptions'=&gt;array( 'style'=&gt;'height:20px;' ), )); ?&gt; &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt; &lt;b&gt;To :&lt;/b&gt; &lt;?php $this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array( 'name'=&gt;'to_date', //'value'=&gt;Yii::app()-&gt;request-&gt;cookies['to_date']-&gt;value, 'options'=&gt;array( 'showAnim'=&gt;'fold', 'dateFormat'=&gt;'yy-mm-dd', ), 'htmlOptions'=&gt;array( 'style'=&gt;'height:20px;' ), )); ?&gt; &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt; &lt;?php echo CHtml::submitButton('Go'); ?&gt; &lt;?php echo CHtml::ajaxSubmitButton('Search', CHtml::normalizeUrl(array('index')), array( 'success'=&gt;'js:' .'function(){' .'$.fn.yiiGridView.update("acc-payment-recei-grid", {url:"index"});' .'}', ), array('id'=&gt;'go', 'name'=&gt;'go')); ?&gt; &lt;?php $this-&gt;endWidget(); ?&gt; &lt;p style="float:right;"&gt; &lt;a href="&lt;?php echo "create"; ?&gt;" class="btn btn-info"&gt;New Payment Receive&lt;/a&gt; &lt;/p&gt; &lt;/div&gt; &lt;style&gt; .items table tr:last-child td:first-child { -moz-border-radius-bottomleft:10px; -webkit-border-bottom-left-radius:10px; border-bottom-left-radius:10px } .items table tr:last-child td:last-child { -moz-border-radius-bottomright:10px; -webkit-border-bottom-right-radius:10px; border-bottom-right-radius:10px } &lt;/style&gt; &lt;?php $this-&gt;widget('zii.widgets.grid.CGridView', array( 'id'=&gt;'acc-payment-recei-grid', 'dataProvider'=&gt;$accpaymentrecei-&gt;search(), //'filter'=&gt;$accpaymentrecei, 'columns'=&gt;array( //'id', array('name' =&gt; 'acc_category_id', 'value'=&gt;'(isset($data-&gt;acccategories-&gt;name)) ? CHtml::encode($data-&gt;acccategories-&gt;name) :""', ), array('name' =&gt; 'acc_recei_id', 'header'=&gt; 'Account Received', //'value'=&gt;'(isset($data-&gt;method)) ? CHtml::encode($data-&gt;method) :""', ), array( 'name' =&gt; 'date', 'value'=&gt;'($data-&gt;date= 0) ? "" : date("d M yy",strtotime($data-&gt;date))', ), array('name' =&gt; 'method', 'value'=&gt;'(isset($data-&gt;method)) ? CHtml::encode($data-&gt;method) :""', ), array('name' =&gt; 'description', //'value'=&gt;'(isset($data-&gt;method)) ? CHtml::encode($data-&gt;method) :""', ), /* 'created_date', 'updated_date', 'file_name', */ array( 'class'=&gt;'CButtonColumn', ), ), )); </code></pre> <p>This is controller </p> <pre><code>public function actionIndex() { $accpaymentrecei=new AccPaymentRecei('search'); $accpaymentrecei-&gt;unsetAttributes(); // clear any default values if(isset($_GET['AccPaymentRecei'])) $accpaymentrecei-&gt;attributes=$_GET['AccPaymentRecei']; $acccategory = AccCategory::model()-&gt;findAll(); $arr_method = array('Cash'=&gt;'Cash', 'Cheque'=&gt;'Cheque', 'Credit Card'=&gt;'Credit Card', 'Bank Transfer'=&gt;'Bank Transfer'); $this-&gt;from_to_date($accpaymentrecei); //exit(); $this-&gt;render('index',array( 'accpaymentrecei'=&gt;$accpaymentrecei, 'acccategory'=&gt;$acccategory, 'arr_method'=&gt;$arr_method, )); } protected function from_to_date($model) { unset(Yii::app()-&gt;request-&gt;cookies['from_date']); // first unset cookie for dates unset(Yii::app()-&gt;request-&gt;cookies['to_date']); //$model=new XyzModel('search'); // your model $model-&gt;unsetAttributes(); // clear any default values if(!empty($_POST)) { Yii::app()-&gt;request-&gt;cookies['from_date'] = new CHttpCookie('from_date', $_POST['from_date']); // define cookie for from_date Yii::app()-&gt;request-&gt;cookies['to_date'] = new CHttpCookie('to_date', $_POST['to_date']); $model-&gt;from_date = $_POST['from_date']; $model-&gt;to_date = $_POST['to_date']; }else{ Yii::app()-&gt;request-&gt;cookies['from_date'] = new CHttpCookie('from_date', date("Y/m/d")); Yii::app()-&gt;request-&gt;cookies['to_date'] = new CHttpCookie('to_date', date("Y/m/d")); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload