Register here!

Forgot password?

ASK NEW QUESTION

Home Page » Zii » List View » RenderPartial w/ CTreeView & CListView (many saves)
0 Votes
Vote Con!

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

  1. echo $this->renderPartial('clistView',array('dataProvider'=>$dataProvider),true,false);
  2. ...
  3.                 $this->widget('CTreeView',array(
  4.                     'id'=>'menu-treeview',
  5.                     'data'=> $treedata,
  6.                 ));
echo $this->renderPartial('clistView',array('dataProvider'=>$dataProvider),true,false); 
...
				$this->widget('CTreeView',array(
				    'id'=>'menu-treeview',
				    'data'=> $treedata,
				));

In controller actionUpdateAjax($id)

  1. ...
  2. Yii::app()->clientscript->scriptMap['jquery.js'] = false;
  3. ...
  4. $this->renderPartial('clistView', array('dataProvider'=>$dataProvider,) , false, true);
  5. ...
...
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

  1.             echo CHtml::ajaxLink('Add to cart' , array('/anuncios/AjaxAnadir', 'id'=>$data->id),  array('update' => '#data',
  2.             '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

 

Answers (1)

  1. 0 votes

    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

© YiiAnswers.com 2011. All rights reserved.

Switch to our mobile site