Clistview Pagination And Slidetoggle()

there is a hidden div(display:none) and a button to make the div slideTonggle()

in the div is a clistview.

i click the button to make the div toggle to show up, and then i click page 2, then the div automatically toggles to be hidden. Why? How to keep the div show up???

if the div is no longer in the document tree how is it that possible for that damn div to be visible

Post your view code please, including the js

hi here is the code




<div class="post-comment">

	<a class="comment-count" onclick="$(this).next().slideToggle();"><span><?php echo $data->answerCount;?></span> Answer<?php echo $data->answerCount>1?'s':'';?></a>

	<div class="comment-list">

		<form class="a-form">

			<textarea name="Answer[description]" id="Answer_description"></textarea>

			<input type="hidden" name="Answer[ask_id]" id="Answer_ask_id" value="<?php echo $data->id;?>">

			<a class="btn addAnswer-btn">Add</a>

		</form>

		<?php $this->widget('zii.widgets.CListView', array(

			'id' => 'answer-list',

			'dataProvider'=>new CArrayDataProvider($data->answers, array(

				'keyField'=>'id',

				'pagination' => array(

					'pageSize' => 5,

				),

			)),

			'itemView' => '/answer/_view',

			'summaryText' => '',

		));?>

    </div>

</div>



(btw, the second line:


<span><?php echo $data->answerCount;?></span>

, how can i update it when successfully submit the form?)




$('.addAnswer-btn').live('click', function() {

	$.ajax({

		type: 'POST',

		url: '/xxx/index.php/answer/create',

		data: $(this).closest('.a-form').serialize(),

		success: function(data) {

			$('input[type=text], textarea').val('');

		//	$.fn.yiiListView.update($(this).closest('a-form').next(), {

		// this part does not work now either, 

		//		data: $(this).serialize()

		//	});

		}

	});

});



Why "the div is no longer in the document tree"?

It has been some time that you have posted this and probably you have a solution, but just to help others with similar issues:

Because client side changes are not carried explicitly. You may need to store the status of the div and set it from that variable every time a new page is loaded.




//First add something to save the toggle state every time the state changes. Such as:


<a class="comment-count" onclick="$(this).next().slideToggle();toggleState=$(this).next().is(':visible')">


//then add some javascript function to be called every page load like this


Yii::app()->clientScript->registerScript('script', <<<JS

  toggleState=false;

  function addJSFunctions(){

       ...

    $(".comment-list").toggle((toggleState)?"visible":"hidden");

  }

  addJSFunctions();

          

JS

        , CClientScript::POS_READY);



Then add to your CListView widget




'afterAjaxUpdate' => 'function (id,data) {

            addJSFunctions(); 

            }'