Yii And Ajax

Hiya All.

I have been searching through the web for an answer for my issue, with very little success.

Here is what i am trying to do.

I have a Grid view at the top of the page showing a list of clients.

In the second half of the page i have TbTab widget.

What i would like to do, is click on any row in the table and the information from that row and other related information appears in the tab below.

Here is the code i have so far but it isn’t working

admin.php




<?php $this->widget('bootstrap.widgets.TbExtendedGridView', array(

	'sortableRows'=>true,

   'afterSortableUpdate' => 'js:function(id, position){ console.log("id: "+id+", position:"+position);}',

	'selectableRows'=>1,

	//'selectionChanged'=>'function(id){ location.href = "'.$this->createUrl('view').'/id/"+$.fn.yiiGridView.getSelection(id);}',

	'type'=>'striped bordered',

	'dataProvider' => $model->search(),

	'columns' => array(

	array(

	        'name'=>'View',

	        'type'=>'raw',

	        'value'=>'CHtml::ajaxLink("$data->id", "index.php/Accounts/ajaxupdate", array(

	        "data"=>array(

	                   "id"=>$data->id,

	             ),

		             "update"=>"#data",

		        ));',

		),  

		array(

	   	'name'=>'id',

		   'header'=>'ID',

		   'type'=>'raw',

		   'value'=>'$data->id',

		   'htmlOptions'=>array('width'=>'40'),

	   ),

		'name',

		'phone',

		'mobile',

		'type',

		'account_manager',

		'status',

		array(

			'class'=>'bootstrap.widgets.TbButtonColumn',

		),

	),

)); 

require_once 'bottom_tabs.php';



bottom_tabs.php




<?php

$this->widget('bootstrap.widgets.TbTabs', array(

	'type'=>'tabs', // 'tabs' or 'pills'

	'tabs'=>array(

		//array('label'=>'Packages', 'content'=>'packages', 'active'=>true), //$this->renderPartial('_view', array('data'=>$model), true), 'active'=>true),

		array('label' => 'Account Info', 'content' => $this->renderPartial('_view_acc_details', array('data'=>$model), true), 'active'=>true),			

		array('label' => 'Packages', 'items' => array(

			array('label' => 'CLI', 'content' => 'Item1 Content'),

			array('label' => 'Add-ons', 'content' => 'Item2 Content'),

			array('label' => 'Carrier Status', 'content' => 'Item2 Content')

		)),		

		array('label'=>'Wireless', 'content'=>'Profile Content'),

		array('label'=>'Tickets', 'content'=>'Messages Content'),

		array('label' => 'Activities', 'items' => array(

			array('label' => 'Emails', 'content' => 'Item1 Content'),

			array('label' => 'Calls', 'content' => 'Item2 Content'),

		)),	

		array('label'=>'Leads', 'content'=>'Messages Content'),

		array('label' => 'Invoices', 'items' => array(

			array('label' => 'Invoices', 'content' => 'Item1 Content'),

			array('label' => 'Pre-Invoices', 'content' => 'Item2 Content'),

		)),	

		array('label' => 'Payments', 'items' => array(

			array('label' => 'Pay Methods', 'content' => 'Item1 Content'),

			array('label' => 'Payments', 'content' => 'Item2 Content'),

		)),	

		array('label'=>'Returns', 'content'=>'Messages Content'),

		array('label'=>'WiMAX', 'content'=>$this->renderPartial('_view_acc_wimax', array('data'=>$model), true)),

	),

));

?>



_view_acc_details.php




<div id="data">

	<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>

	<?php echo CHtml::encode($data->id); ?>

	<br />


	<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>

	<?php echo CHtml::encode($data->name); ?>

	<br />


	<b><?php echo CHtml::encode($data->getAttributeLabel('phone')); ?>:</b>

	<?php echo CHtml::encode($data->phone); ?>

	<br />


	<b><?php echo CHtml::encode($data->getAttributeLabel('mobile')); ?>:</b>

	<?php echo CHtml::encode($data->mobile); ?>

	<br />

	

	<b><?php echo CHtml::encode($data->getAttributeLabel('email')); ?>:</b>

	<?php echo CHtml::encode($data->email); ?>

	<br />

	<br />


	<br />

</div>



AjaxUpdate funstion




	public function actionAjaxUpdate()

	{

	        if(isset($_GET['id']))

	        {

	        	$model = $this->loadModel($id);

	           $this->renderPartial('_view_acc_details', array('data'=>$model), false, true);

	        }

	}



I am relatively new to YII and appreciate any help.

Many Regards

Liam

Ok All.

I went right back to basics, and i can now have a DIV at the bottom of the page change when i click a ajaxLink.

The issue i have now is that when i go to page 2 or further on the gridview it keeps page 1 links,

so when i am on page 2 and clicking on the details for account 11, it shows me account 1.

Here is the code to allow me to change the details at the bottom of the page

accountcontroller.php




	public function actionIndex1($id)

    {

	        if(isset($_GET['id']))

	        {

	        	$model = $this->loadModel($id);

	           $this->render('index1', array('data'=>$model));

	        }

    }

 

    public function actionUpdateAjax($id)

    {


	        if(isset($_GET['id']))

	        {

	        	$data = $this->loadModel($id);

       		 $this->renderPartial('_ajaxContent', array('data'=>$data));

       	}

    }



index1.php




<?php

$this->widget('bootstrap.widgets.TbExtendedGridView', array(

	'sortableRows'=>true,

   'afterSortableUpdate' => 'js:function(id, position){ console.log("id: "+id+", position:"+position);}',

	'selectableRows'=>1,

	'selectionChanged'=>'function(id)

								{ 

									location.href = "'.$this->createUrl('view').'/id/"+$.fn.yiiGridView.getSelection(id);

								}',

	'type'=>'striped bordered',

	'dataProvider' => $model->search(),

	'columns' => array(

		array(

	   	'name'=>'id',

		   'header'=>'ID',

		   'type'=>'raw',

		   'value'=>'$data->id',

		   'htmlOptions'=>array('width'=>'40'),

	   ),

		'name',

		'phone',

		'mobile',

		'type',

		'account_manager',

		'status',

		array(

			'class'=>'bootstrap.widgets.TbButtonColumn',

		),

		array(

        'header'=>'Actions',

        'type'=>'raw',

        'value'=>'CHtml::ajaxLink("view", 

        									Yii::app()->createUrl("Accounts/UpdateAjax/", array("id"=>+$.fn.yiiGridView.getSelection(id))),

        									array("update"=>"#data"))',

		),

	),

));


?>




<div id="data">

   <?php $this->renderPartial('_ajaxContent', array('data'=>$data)); ?>

</div>

 

<?php echo CHtml::ajaxButton ("Update data",

                              CController::createUrl('Accounts/UpdateAjax/120'), 

                              array('update' => '#data'));

?>



_ajaxContent.php




<?php 

	echo "hi";

if(isset($data))

{


	print_r($data->getAttributes()); 

}	

?>



Last hurdle for me now, all i need is for the links to update and include the new IDs when the page is changed.

Regards

Liam