Yii Framework Forum: Cgridview And Ajax - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cgridview And Ajax Rate Topic: -----

#1 User is offline   pjravs 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 06-February 14

Posted 11 May 2014 - 08:58 PM

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.

VIEW

<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>

<div class="row buttons">
<?php echo CHtml::button('Search..', array('class'=>'btn btn-primary','style'=>'margin-top:-8px;','onclick' => 'searchCode()')); ?>
</div>

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

<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'grid_id',
'dataProvider' => $data2,
'columns' => array(
'id',
'payment',
'datesale',
'code',
),
));
?>
<script>
function searchCode()
{
var account = $("#account").val();
<?php
echo CHtml::ajax(array(
'url'=>array('test'),
'type'=>'post',
'data'=>'js:{account:$("#account").val()}',
'success'=>'function(data){
$.fn.yiiGridView.update("grid_id");
return false;
}',
))
?>
}

</script>


CONTROLLER

public function actionTest() {
$model=new DATATicket2Media;
$rawData=Yii::app()->msdb->createCommand("
SELECT
DATA_Transaction.TransactionId AS id,
DATA_Payment.PaymentAmount AS payment,
DATA_Sale.SaleDate AS datesale,
DATA_MediaIdentifier.IdentifierCode AS code
FROM
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
WHERE
DATA_MediaIdentifier.IdentifierCode = 'EBE0K0XQO0008Q'")->queryAll();

$data2=new CArrayDataProvider($rawData, array(
'id'=>'user',
'sort'=>array(
'attributes'=>array(
'id', 'username', 'email',
),
),
'pagination'=>array(
'pageSize'=>10,
),
));

$this->render('create', array(
'model' => $model,
'data2'=>$data2,
'grid_id' => '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!
Thanks!
0

#2 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 488
  • Joined: 08-October 12
  • Location:Austria

Posted 12 May 2014 - 02:41 AM

This is the way to updated cgridview after ajax

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

	'afterAjaxUpdate'=>'function(id, data){
		console.log($(".selected").text());
}',



Javascript to call update is


	$.fn.yiiGridView.update('programm-grid', {
		data:$(this).serialize()
	});

Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

#3 User is offline   pjravs 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 06-February 14

Posted 12 May 2014 - 03:18 AM

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!
0

#4 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 488
  • Joined: 08-October 12
  • Location:Austria

Posted 13 May 2014 - 02:52 AM

Hi try thishttp://www.yiiframework.com/forum/index.php/topic/31221-how-to-update-cgridview-with-ajax/
Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users