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("
[left] 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();[/left]
[left]$data2=new CArrayDataProvider($rawData, array(
'id'=>'user',
'sort'=>array(
'attributes'=>array(
'id', 'username', 'email',
),
),
'pagination'=>array(
'pageSize'=>10,
),
));[/left]
$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!