Yii Framework Forum: CListView with ajaxLink - Yii Framework Forum

Jump to content

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

CListView with ajaxLink Rate Topic: -----

#1 User is offline   lgoss007 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 01-October 09

Posted 18 February 2010 - 05:11 PM

I have a two column view. The left view I want to render a CListView with links to the 2nd column which is sort of a detail view. For example:

// mainView.php
<div id="left">
  <!-- render a list of people for instance -->
  <?php $this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider, 'itemView'=>'subView'));
</div>

<div id="right">
  <?php $this->renderPartial('personDetail', array('model'=>$model)); ?>
</div>


In the subView I create an ajaxLink like so:

// itemView.php
echo CHtml::ajaxLink(
  $data->name,
  CController::createUrl('person/index'),
  array(
    'data'=>array('id'=>$data->id),
    'update'=>'#right'
  )
);


This works fine to populate the right side with data until I sort or go to the next link.. at which point the ajaxLink is broken and no longer works. I can't find how the links are being broken. Is there a better way to approach this?
0

#2 User is offline   khonggiannet 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 21-May 09

Posted 19 February 2010 - 10:54 AM

I had the same problem. Special thank for any help.
Everything having a beginning has an end!
0

#3 User is offline   lgoss007 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 01-October 09

Posted 19 February 2010 - 01:36 PM

Haven't figured it out yet..

Looking it up in firebug I notice that once clicking on sorting or paging my links from the subView are no longer a url but just a "#". But I don't know why the subView isn't updating the url's properly.. maybe ajaxLinks can't be updated on a partial of the page since they need to add javascript to the end.. can that be done manually?

Tried a static version by setting ajaxUpdate to false but...

Then it kills the contents on the right if you sort or click on another page of course. To get it to work like this you have to change your links to include paging and sorting parameters.. but I can't figure that out either.. can that be done in the subView (need to get the paging and sorting params for links)? Otherwise clicking on a link in the subview will reset the contents on the left.

Any ideas on how to solve this.. static or ajax? The difficult part is that this page is generated from a search of multiple fields (name, age, sex, race..), so those parameters have to be passed to the detail view (along with the sort and paging) in order to generate the correct url.
0

#4 User is offline   lgoss007 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 01-October 09

Posted 19 February 2010 - 02:41 PM

Well I got it working with ajax.. just had to leave the confines of Yii. So I replaced my view with this custom ajax link instead:

// itemView.php
<a
  href="index.php?r=person/index#"
  onclick="jQuery.ajax({
    'data':{'id':'<?php echo $data->id; ?>'},
    'url':'/app/index.php?r=person/detail',
    'cache':false,
    'success':function(html){jQuery('#right').html(html)}
  });">
  <?php echo $data->name; ?>
</a>

1

#5 User is offline   khonggiannet 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 21-May 09

Posted 19 February 2010 - 06:08 PM

Thank you very much. I understood. When using CHtml::ajaxLink, javascript is appended at the bottom of page, so it is expried when a new part of page is loaded via ajax. If we declare javascript in onclick property, the problem is solved.
Everything having a beginning has an end!
0

#6 User is offline   Blue Sky Love 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-May 11

Posted 09 May 2011 - 02:44 AM

Thank.
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