RenderPartial w/ CTreeView & CListView (many saves)
CListViewCTreeViewrenderPartial
Hello all,
On my web app I have two sections:
– right hand side (CTreeView) : categories
– middle section (ClistView) : items for that category
Once you click on any link of CTreeView (which are composed of ajaxLink) the CListView gets refreshed w/ desired data.
Here is part of code
View
- echo $this->renderPartial('clistView',array('dataProvider'=>$dataProvider),true,false);
- ...
- $this->widget('CTreeView',array(
- 'id'=>'menu-treeview',
- 'data'=> $treedata,
- ));
echo $this->renderPartial('clistView',array('dataProvider'=>$dataProvider),true,false);
...
$this->widget('CTreeView',array(
'id'=>'menu-treeview',
'data'=> $treedata,
));In controller actionUpdateAjax($id)
- ...
- Yii::app()->clientscript->scriptMap['jquery.js'] = false;
- ...
- $this->renderPartial('clistView', array('dataProvider'=>$dataProvider,) , false, true);
- ...
...
Yii::app()->clientscript->scriptMap['jquery.js'] = false;
...
$this->renderPartial('clistView', array('dataProvider'=>$dataProvider,) , false, true);
...This works perfectly.
Now I added another ajaxLink inside the CListView which adds item to cart.
View code: inside ‘itemView’=>’_view’, of CListView
- echo CHtml::ajaxLink('Add to cart' , array('/anuncios/AjaxAnadir', 'id'=>$data->id), array('update' => '#data',
- 'complete' =>'function(data){ return false;}' ));
echo CHtml::ajaxLink('Add to cart' , array('/anuncios/AjaxAnadir', 'id'=>$data->id), array('update' => '#data',
'complete' =>'function(data){ return false;}' ));Now whenever I click (the right side link) it works the first time but then adds Items to cart (like crazy), causing sometimes the browser to crash.
Things I have done:
Yii::app()->clientscript->scriptMap['jquery.js'] = false;
Tried using ajaxSubmitButton instead of ajaxLink.
Neither have worked.
Things I have noticed:
1.- The Ajax ID gets repeated after the second time the navigation (right hand side) is clicked.
That is (the very 1st time)
The (right hand side) Ajax links gets id (yt0 -> yt12)
The (middle section) gets Ajax links yt14-> …
But whenever the right side (navigation) link is clicked again.
The middle section gets refreshed but Ajax (id) links starts w/ yt0.
Thus repeating yt0 both on navigation and add to cart option.
I imagine this is part of the problems?
The thing is that whenever I click a navigation link (right hand side) apart from updating it calls AjaxAnadir many times. And it saves not only (one item) but a many different items. Why? No clue.
Possible Solutions:
- Don’t create ajax link to add things to cart. Use CHtml::link. But how to render to same page (w/ all filters, so as user gets sent to exactly same page/position/filter) ?
- make ajaxLink numbering start w/ different id’s . Instead of yt1 ==> navigation_yt1 … How?
Thanks in advance
By tuolden in List View · Asked 574 days 4 hours 57 mins ago
Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0
Possibly related Questions
-
Ajax Cform validation within renderPartial view
February 7, 2012 By TheDeveloper 4 Answers
TAGS
actioncreate ( x 2 )ACTIVERECORD ( x 4 )AJAX ( x 10 )ajaxSubmitButton ( x 4 )AR ( x 2 )cactivedataprovider ( x 2 )CActiveForm ( x 2 )cactiverecord ( x 2 )CGridView ( x 14 )CJuiAutoComplete ( x 3 )CJuiDialog ( x 8 )CListView ( x 8 )controller ( x 7 )Css ( x 2 )CStarRating ( x 2 )CTreeView ( x 2 )database ( x 5 )dialog ( x 2 )dropdownlist ( x 3 )EGMaps ( x 3 )extension ( x 3 )file ( x 2 )form ( x 6 )Giix ( x 2 )gridview ( x 2 )html ( x 2 )javascript ( x 3 )many_many ( x 4 )merge ( x 2 )model ( x 4 )Modules ( x 3 )multilanguage ( x 2 )php ( x 2 )redirect ( x 4 )Registration ( x 3 )relations ( x 5 )renderPartial ( x 8 )session ( x 2 )sorting ( x 3 )sql ( x 4 )url ( x 3 )urlManager ( x 3 )validation ( x 3 )yii ( x 11 )YiiAnswers Site ( x 4 )This website counts Questions and 429 Answers by 7438 registered users.

From what i read it is an obvious issue of duplicating function binding. Make sure the content returned via AJAX doesn’t process its output.
Maybe it is better to use a registered function on your main layout that will take care of buttons / links with .live() jquery instead of AJAX’ed contents with ajax buttons.
By tonydspaniard · 573 days 15 hours 16 mins ago
Questions: 2 Accepted: 0 ( 0% ) | Reputation: 0