Yii Framework Forum: Property "cgridview.ajaxupdate" Is Not Defined. - Yii Framework Forum

Jump to content

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

Property "cgridview.ajaxupdate" Is Not Defined. Rate Topic: -----

#1 User is offline   AussieNeil 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 25-January 13

Posted 25 January 2013 - 07:03 PM

Hi,

I am trying to get Dynamic parent and child CGridView on single view working. I have tried to follow this article:

http://www.yiiframew...ew-was-clicked/

but I have failed as I get the above error.

Now I am an experienced programmer but am learning PHP, java and the yii framework all on the fly. So I may be attempting too much but hey I like a good challenge.

The difference for me is also that my tables are a one to many relationship.

So I have a Section with many breeds.

This is my models:

rabbitsection
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('RabbitSectionName, RabbitSectionOrder', 'required'),
array('RabbitSectionOrder', 'numerical', 'integerOnly'=>true),
array('RabbitSectionName', 'length', 'max'=>100),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('RabbitSectionId, RabbitSectionName, RabbitSectionOrder', 'safe', 'on'=>'search'),
);
}

rabbitbreed
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('RabbitBreedName, RabbitBreedOrder, RabbitSectionId', 'required'),
array('RabbitBreedOrder, RabbitSectionId', 'numerical', 'integerOnly'=>true),
array('RabbitBreedName', 'length', 'max'=>100),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('RabbitBreedId, RabbitBreedName, RabbitBreedOrder, RabbitSectionId', 'safe', 'on'=>'search'),
);
}


admin.php
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$rabbitsection_model,
)); ?>
</div><!-- search-form -->

<div id="sectionView">
/*
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'rabbitsection-grid',
'dataProvider'=>$rabbitsection_model->search(),
'filter'=>$rabbitsection_model,
'columns'=>array(
'RabbitSectionId',
'RabbitSectionName',
'RabbitSectionOrder',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
*/
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'rabbitsection-grid',
'dataProvider'=>$rabbitsection_model->search(),
'filter'=>$rabbitsection_model,
'columns'=>array(
'RabbitSectionId',
'RabbitSectionName',
'RabbitSectionOrder',
array(
'class'=>'CButtonColumn',
),
),
'ajaxupdate' => 'rabbitbreed-grid',
)); ?>
</div>

<!-- The childView <div>, renders the _child form, which contains the Child Gridview.
The ajax response will replace/update the whole <div> and not just the gridview. -->
<div id="rabbitbreedView">
<?php
$this->renderPartial('_rabbitbreed', array(
'rabbitbreed_model' => $rabbitbreed_model,
'rabbitsectionID' => $rabbitsectionID,
))
?>
</div>

<?php
/*Load the javascript file that contains our own ajax function*/
$path = Yii::app()->baseUrl.'/js/customFunctions.js';
Yii::app()->clientScript->registerScriptFile($path,
CClientScript::POS_END);
?>

_rabbitbreed.php (in view folder of rabbitsection)

<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'rabbitbreed-grid',
'dataProvider'=>$rabbitbreed_model->searchIncludingPermissions($rabbitsectionID),
'filter'=>$rabbitbreed_model,
'columns'=>array(
'rabbitbreeedid',
array(
'name'=>'RabbitSectionName',
'value'=>'RabbitSectionName', /* Test for
empty related fields not to crash the program */
'header'=>'Breed',
'filter' => CHtml::activeTextField($rabbitbreed_model,
'rabbitsectionName'),
),
array(
'class'=>'CButtonColumn',
'template'=>'{view}{update}{delete}',
'viewButtonUrl' => 'array("rabbitbreed/view",
"id"=>$data->rabbitbreedid)',
'updateButtonUrl' => 'array("rabbitbreed/update",
"id"=>$data->rabbitbreedid)',
'deleteButtonUrl' => 'array("rabbitbreed/delete",
"id"=>$data->rabbitbreedid)',
),
),
));
?>

RabbitsectionController.php
public function actionAdmin()
{
$rabbitsection_model = new Rabbitsection('search');
$rabbitsection_model->unsetAttributes();

if (isset($_GET['Rabbitsection']))
$rabbitsection_model->attributes=$_GET['Rabbitsection'];

if(!isset($_GET['RabbitSectionId'])){
$group="A";
$criteria=new CDbCriteria;
$criteria->compare('RabbitSectionId',$rabbitsection_model->RabbitSectionId,TRUE);
$criteria->compare('rabbitsectionName', $rabbitsection_model->RabbitSectionName,TRUE);
$dataProvider = new CActiveDataProvider('rabbitsection', array(
'criteria'=>$criteria,
));

If (count($dataProvider->getData())>0){
$first_model =$dataProvider->getData();
$rabbitsectionid = $first_model[0]->RabbitSectionId;
}
else{
$rabbitsectionid = 0;
}
}
else{
$group = "B";
$rabbitsectionid = $_GET['RabbitSectionId'];
}
$rabbitbreed_model = new Rabbitbreed("searchIncludingBreeds($rabbitsectionid");
$rabbitbreed_model->unsetAttributes();
$rabbitbreed_model->scenario = 'searchIncludingBreeds';
if(isset($_GET["Rabbitsection"]))
$rabbitbreed_model->attributes=$_GET["Rabbitsection"];

if ($group=="A"){
$this->render('admin', array(
'rabbitsection_model'=>$rabbitsection_model,
'rabbitbreed_model'=>$rabbitbreed_model,
'RabbitSectionId'=>$rabbitsectionid,
));
}
else{
$this->renderPartial('_rabbitbreed', array(
'rabbitbreed_model'=>$rabbitbreed_model,
'RabbitSectionId' => $rabbitsectionid,
));
}
}

And I have put the ajax code into a customFunctions.js in a js subfolder.

Now this is where I think I have gone wrong and which is not clear in the article. How do I define the js code in the customFunctions.js?

Or do I have it totally wrong?
0

#2 User is offline   Liam Carter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 30-August 12

Posted 28 January 2013 - 03:35 PM

Hiya.

I have only ever used Ajax update on a CGridView with the parameter
true


But a possible mistake is it should be

'ajaxUpdate' => 'rabbitbreed-grid',


not

'ajaxupdate' => 'rabbitbreed-grid',


Capital "U"

Could you explain a bit more of what you are trying to achieve.

Regards

Liam
0

#3 User is offline   AussieNeil 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 25-January 13

Posted 29 January 2013 - 02:33 PM

Hi Liam,

Thanks for that. That was the problem....Should have looked at my version of the code closer.

However, I have only moved slightly further forward.

I am having trouble converting the code but I am getting there slowly, I think.

What I am trying to achieve is to have two grids that are linked (actually eventually I want four).The first grid has a list of sections with the second grid having breeds. When a Section is highlighted I want the second grid to have the breeds linked to that section. I was trying to base it around the article mentioned above but it was a many to many and I am using a one to many relationship.
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