Cgridview And Ajax

Good Day YII!

I have a problem in using both cgriview and ajax. I wanted to update my Cgridview using ajax after submitting an input in the textbox. Currently, I have this code.


<div class="row">

<?php echo 'Identifier Code : ?>

<?php echo CHtml::textField(‘account’,’’,array(‘size’=>60,‘maxlength’=>155,‘placeholder’=>‘Enter Account Here…’,‘style’=>‘width:20em;’)); ?>


<div class="row buttons">

<?php echo CHtml::button(‘Search…’, array(‘class’=>‘btn btn-primary’,‘style’=>‘margin-top:-8px;’,‘onclick’ => ‘searchCode()’)); ?>


<div class="account_details"></div>


$this->widget(‘zii.widgets.grid.CGridView’, array(

‘id’ => ‘grid_id’,

‘dataProvider’ => $data2,

‘columns’ => array(









function searchCode()


	var account = &#036;(&quot;#account&quot;).val();


	echo CHtml::ajax(array(






				return false;					







public function actionTest() {

$model=new DATATicket2Media;


			 [left] SELECT 

				  DATA_Transaction.TransactionId AS id,

				  DATA_Payment.PaymentAmount AS payment,

				  DATA_Sale.SaleDate AS datesale,

				  DATA_MediaIdentifier.IdentifierCode AS code


				  DATA_MediaIdentifier LEFT JOIN

				  DATA_Media ON DATA_MediaIdentifier.MediaId = DATA_Media.MediaId LEFT JOIN

				  DATA_Ticket2Media ON DATA_Media.MediaId = DATA_Ticket2Media.MediaId LEFT JOIN 

				  DATA_Ticket ON DATA_Ticket2Media.TicketId = DATA_Ticket.TicketId LEFT JOIN 

				  DATA_Account ON DATA_Ticket.AccountId = DATA_Account.AccountId LEFT JOIN

				  DATA_Reservation ON DATA_Reservation.AccountId = DATA_Account.AccountId LEFT JOIN						 

				  DATA_Sale ON DATA_Reservation.SaleId = DATA_Sale.SaleId LEFT JOIN

				  DATA_Transaction ON DATA_Sale.SaleId = DATA_Transaction.SaleId LEFT JOIN

				  DATA_Payment ON DATA_Transaction.TransactionId = DATA_Payment.TransactionId 


			  	  DATA_MediaIdentifier.IdentifierCode = 'EBE0K0XQO0008Q'&quot;)-&gt;queryAll();[/left]

	[left]&#036;data2=new CArrayDataProvider(&#036;rawData, array(




         		'id', 'username', 'email',







  &#036;this-&gt;render('create', array(

  'model' =&gt; &#036;model,


    'grid_id' =&gt; 'grid_id',


I just want to have some idea on how to update a cgridview using ajax and depending on the user it will bind the value to a query in the controller. Hope someone could help!


This is the way to updated cgridview after ajax

$this->widget('zii.widgets.grid.CGridView', array(

	'afterAjaxUpdate'=>'function(id, data){



Javascript to call update is

	$.fn.yiiGridView.update('programm-grid', {



Thanks for the reply!

But do I need to add render code in my controller after ajax Request to update the content of my CGridView?

Do you have any sample that I can refer to?

Thanks Chandran!

Hi try this