Cgridview Cell Renderpartial A Form

Hello Yii lovers,

I face problem of rendering a form in a view.

At first my view should be displayed like this

4452

before select.png

then, if user clicks one of the Name in the table, there will be generated a form like this

4453

after select.png

There are 3 data in the table, but whatever I click, it still displays the same id…

For example, if I click the 137 Refreshing Guest Room, the right form displays detailed data of 137 Refreshing Guest Room.

It also only displays detailed data of 137 Refreshing Guest Room when I click the 1 Swimming Pool.

It is because this line

12 is the id of Refreshing Guest Room.

I wanna grab dynamic id from selected data, but it has no result.

If I change ‘model’=>$this->loadModel(12),

into

‘model’=>$this->loadModel($data->id),, it will result error => Undefined variable: data.

It’s sure because the above line is outside the cgridview widget.

As the cgridview successful to display, there is no problem in $dataprovider. I’ve already define $dataProvider in my controller. So what should I do to grab id of selected row?

These are full codes in my view




<?php Yii::app()->clientScript->registerScript('view', "

$('.edit-button').click(function(){

	$('.edit-form').toggle();

	return false;

});

$('.edit-form form').submit(function(){

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

		data: $(this).serialize()

	});

	return false;

});

");

?>

<div class="row">

	<div class="small-6 columns">

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

			 'id'=>'facility-grid',

			 'dataProvider'=>$dataProvider,

			 'template'=>"{items}",

			 'columns'=>array(

					array('name'=>'id','header'=>'Name', 'type'=>'raw','value'=>'CHtml::link(CHtml::encode($data->quantity . " " . $data->name),array("#","id"=>$data->id),array("class"=>"edit-button"))'),

					'description',

			 ),

		)); 

		?>	

	</div>

	

	<div class="small-6 columns">

		<div class="edit-form" style="display:none">

		<?php $this->renderPartial('_ajax_form_disable',array(

			'model'=>$this->loadModel(12),

		)); ?>

		</div>

	</div>

</div>



Thanks for your attention ^^

Hi

u can check this

http://www.yiiframework.com/forum/index.php/topic/33222-click-event/

hope this help

Thanks Ankit for your reply

I’ve tried to move it, but it still results error -> Undefined variable: data

I wish it help

u can call a ajax on jquery


'$(".down-link").bind("click",function(){

			alert("test");

			var id = this.id

			 $.ajax({

				type: "GET",

				url: "<?php echo CController:<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />'test'); ?>";

				data:{"id":id}

				success: function(result) {

				    $('#content1').html(result); 

				      }

			      });

		}

		)');

i wonder why the id still cannot be recognized :(