Yii Framework Forum: Why my CGridView sometimes cannot be selected? - Yii Framework Forum

Jump to content

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

Why my CGridView sometimes cannot be selected? Rate Topic: -----

#1 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 06 July 2010 - 10:53 PM

I use CGridView to view with ajax, but I don't know why sometimes the CGridView cannot be selected. My code is like this.

//in /controllers/BarangController.php
 
...
public function actionCariBarang(){
	$model=new Barang('search');
	if( isset($_GET['inputField']) ){
		$inputField=$_GET['inputField'];
	}
	
	if(isset($_GET['Barang'])) {
		$attributes = $_GET['Barang'];
		$model->attributes=$attributes;
	}                                                                                                    
	
	$this->renderPartial('caribarang',array(
	'model'=>$model,
	'inputField'=>$inputField,
	),false,true);
}
....


 
//in /views/barang/caribarang.php
//this is what I am going to show 
<?php
$dp = $model->search();
      $dp->keyAttribute='id';
      $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'barang-grid',
        'dataProvider'=>$dp,
        'filter'=>$model,
        'columns'=>array(
                array(
                  'name'=>'id',
                  'value'=>'$data->id',
                ),
                'nama',
                'nilai_satuan',
                'satuan',
        ),
));?>

<div class="row button" align="right">
<?php
echo CHtml::ajaxButton('Select','',
        array('success'=>'js:function() {
            var p_sel = $.fn.yiiGridView.getSelection("barang-grid");
            if ( p_sel != "") {
                $("#dialog_ground").html("");
                $("#'.$inputField.'").val(p_sel);
            }
        }'),array('id'=>'selectButton')); 
      
?>
</div>


	
//in my /views/purchaseOrderDet/_form.php
//at here I am calling the ajax which will call the actionCariBarang() and show the viewbarang.php 
        ... 
        <div class="row">
		<?php echo $form->labelEx($model,'barang_id'); ?>
		<?php echo $form->textField($model,'barang_id'); ?>
		<?php 
		echo CHtml::ajaxLink('Pilih Barang', $this->createUrl('/Barang/cariBarang',
                array('inputField'=>'PurchaseOrderDet_barang_id')),
                array('update'=>'#dialog_ground'),
                array('id'=>'senderDialog',)); ?> 
		<?php echo $form->error($model,'barang_id'); ?>
		<div id="dialog_ground" ></div>
	</div>
        ...

“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#2 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 08 July 2010 - 12:50 PM

At last I figured out the source of problem. There is problem in my code.

Everytime I click the ajaxLink, it will call actionCariBarang() which will show view file caribarang.php. What I later realised is, everytime I call CGridView, it will include the javascript once again. If I click ajaxlink once again, it will load the CGridView again which in turn load the javascript once again. Meaning there are more than one same javascripts running already. Meaning if I click the CGridView once, it will run the script twice!!, causing the "selected" class in the div disappear immediately after been added.

So, later in order to prevent it load more than once, I load the CGridView once, and then hide it using css. By this way, if I want to show the CGridView again, I just need to change the css via javascript. I think this is the only solution that I can use now...
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
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