Yii Framework Forum: Meng-update CGridview melalui CJuiDialog - Yii Framework Forum

Jump to content

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

Meng-update CGridview melalui CJuiDialog Rate Topic: -----

#1 User is offline   edoriansyah 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 25-March 11
  • Location:Depok, Indonesia

Posted 25 March 2011 - 08:18 AM

Halloo kawan2,
Saya punya masalah tentang cara meng-update CGridView melalui CJuiDialog yang mana pada CJuiDialog melakukan suatu input data.
Selanjutnya data akan tersimpan di CGridView lalu setelah data tersimpan secara otomatis CGridView akan meng-update dan menampilkan data yang baru saja dibuat. Berikut merupakan sepenggal kode saya:

Ini merupakan clientScript yg saya daftarkan utk melakukan update CGridView
Yii::app()->clientScript->registerScript('mrqitem', "
$('.link-form form').submit(function(){
	$.fn.yiiGridView.update('mrq-item-grid', {
		data: $(this).serialize()
	});
	return false;
});

Ini merupakan ajaxlink yg akan menampilkan CJuiDialog
<div class="link-form">
<?php echo CHtml::ajaxlink(Yii::t('mrqitem','Add Item'),$this->createUrl('mrqItem/createitem'),array('id_mrq'=>$mrq['id'],
                    'onclick'=>'$("#MrqitemDialog").dialog("open"); return false;',
                    'update'=>'#MrqitemDialog'
                    ),array('id'=>'showMrqitemDialog')); ?>
<div id="MrqitemDialog"></div>
</div><!-- link-form -->

Berikutnya merupakan method Createitem yg ada pada controller mrqItemController
public function actionCreateitem() {
            $model=new MrqItem;
       		// Ajax Validation enabled
        	$this->performAjaxValidation($model);
        	// Flag to know if we will render the form or try to add
        	// new jon.
                $flag=true;
        	if(isset($_POST['MrqItem']))
        	{       $flag=false;
            		$model->attributes=$_POST['MrqItem'];
                        $model->save();
                }
                if($flag) {
                    $this->renderPartial('createMrqitem',array('model'=>$model,),false,true);
                }
}

Yang terakhir form untuk tampilan CJuiDialog
<div class="form" id="MrqitemDialogForm">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'mrq-item-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
        
	<?php echo $form->hiddenField($model,'id_mrq');?>
	

	<div class="row">
		<?php echo $form->labelEx($model,'id_item'); ?>
		<?php echo $form->dropDownList($model,'id_item',CHtml::listData(Item::model()->findAll(),'id','nama'),array('prompt'=>'Select')); ?>
		<?php echo $form->error($model,'id_item'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'qty'); ?>
		<?php echo $form->textField($model,'qty',array('size'=>10,'maxlength'=>10)); ?>
		<?php echo $form->error($model,'qty'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'id_satuan'); ?>
		<?php echo $form->dropDownList($model,'id_satuan',CHtml::listData(Satuan::model()->findAll(),'id','nama'),array('prompt'=>'Select')); ?>
		<?php echo $form->error($model,'id_satuan'); ?>
	</div>

	<div class="row-buttons">
		<?php echo CHtml::ajaxSubmitButton(Yii::t('mrqitem', 'Create item'),
                        CHtml::normalizeUrl(array('mrqItem/createitem','id_mrq'=>$mrq['id'],'render'=>false)),
                        array('success'=>'js:function(data) {
                                $("#mrq-item-grid").val(data);
                                $("#MrqitemDialog").dialog("close");
                                }'),array('id'=>'closeMrqitemDialog')); ?>
	</div>
     
<?php $this->endWidget(); ?>

</div><!-- form -->

Masalah yang masih saya hadapi ialah data masih belum tersimpan pada database
dan saya ingin tahu bagaimana cara melakukan update/refresh pada CGridView. :wacko:
Mohon dari kawan2 sekalian pencerahan dan bantuannya. Terima kasih :D
Yii-Pii
0

#2 User is offline   Br4m 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 25-October 10

Posted 25 March 2011 - 08:41 AM

Hello edoriansyah,

May be this is the similiar case what you want to:

1. How to call cjuidialog in cgridview.

2. Data Picker.
0

#3 User is offline   edoriansyah 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 25-March 11
  • Location:Depok, Indonesia

Posted 28 March 2011 - 05:24 AM

View PostBr4m, on 25 March 2011 - 08:41 AM, said:

Hello edoriansyah,

May be this is the similiar case what you want to:

1. How to call cjuidialog in cgridview.

2. Data Picker.


Thanks for the respond Br4m.
url # 1 is almost similar. But the reverse of what I want because I'm looking for How about to call cgridview in cjuidialog?
I mean update cgridview through cjuidialog.. have idea?
Yii-Pii
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