Loading CListview by ajax = the CListview js and css is missing, and pagination links load the partial

For simplicity lets say I have a page on which I have a jui tabs widget, and the tab contents is loaded by ajax. The tab contents consists of a CListview (with pagination).

Unfortunately this way its JS and CSS files aren’t loaded. Also the pagination by ajax of the CListview is broken(for the same reason) so the clicking on the pagination link makes the browser load the url of the partial.

Any way to fix this, or to go around ?

I’m not quite sure what your code looks like, but wherever you have the renderPartial for the tab’s ajax call that displays the tab contents, try


$this->renderPartial('someview',array('data'=>$data),false,true);

The ‘false,true’ should force it to load the CSS and JS files you need. I’ve gotten around most of my AJAX problems just by adding those parameters wherever I have AJAX content being rendered.

That fixed it indeed. Thank you.

It seams, i have an eqaual problem.

There is an CJuiTab widget with 2 Tabs.

1st tab with static content:


 

$tabs["Rss"]=$this->widget('zii.widgets.CListView', 

array(

'dataProvider'=>$dataProvider,

'itemView'=>'_view_rss',

'ajaxUpdate'=>false,

),true); 



2nd tab is an Ajax Request




$tabs["Msg"]=array('ajax'=>CController::createUrl('TMsg/AjaxLoadList',array('objekt'=>"TMsg")));

Building the Widget:




$tabWidget=$this->widget('zii.widgets.jui.CJuiTabs', array(

'tabs'=>array(

'Rss'=>array('content'=>$tabs["Rss"],'id'=>'tabRss'),

'Msg'=>$tabs["Msg"]

),

'options'=>array(

'collapsible'=>true,

),

));

The Action TMsg/AjaxLoadList returns an CListView eaqual to the static tab:




[...](loading Data)

$this->renderPartial('_viewTMsg’,array(

'dataProvider'=>$dataProvider

),false,true);



At the end there are 2 tabs with CListView data insight. The content oft those CListView are News headlines. Each row of this CListView is an Ajax Link to open an CJuiDialog to load the whole News into the dialog useing Ajax.

The problem/situation:

1.) Tab Rss (static Tab) is active, CListView shows the Headlines, everything works fine.

2.) By clicking the (e.g. 1st) CListView row, the CJuiDialog opens and the Message ist loading into the CJuiDialog. (fine)

3.) I select tab Msg (ajax tab), the CListView is loaded and displayed. (also fine)

4.) If i select (click on ) a Msg CListView Row e.g. also the 1st row, the CJuiDialog opens and 1 Ajax request received the 1st Message AND(!) at the same time the CJuiDalog from the 1st row oft CListView static tab "Rss" opend again!

5.) If i go to step 1-2 same Problem: a click on the 1st row in the static tab opends the 1st CJuiDalog from static Rss CListView AND Ajax Msg CListView

Every time i switch between static and Ajax tab, one more Ajax requast will be fired to receive the Message if i click a row.

Example: if i switch 10 times between static tab and Ajax tab in order to select an CListView row, the Ajax action "TMsg/AjaxLoadList" is called 10 times, but "only" two CJuiDialogs (1x Rss and 1x Msg) are opend.

May anyone have an advice or help for this problem?

Thank You

Didn’t work for me (work for css but no for pagination links). I have widget and it load CListView using ajax (like in this example http://www.yiiframework.com/wiki/49/update-content-in-ajax-with-partialrender/ )

but after CListView loaded pagination looks like UpdateAjax?Conv_page=2 but current action is Index.

BTW css is OK, but pagination isn’t

Any ideas ?

Here is my code:

Controller:


public function actionIndex()

    {

		$dataProviderConv=$this->loadconv();

        $this->renderPartial('index', array(

                'dataProviderConv'=>$dataProviderConv,

        ),false,true); 

    }

public function actionUpdateAjax()

    {

		

		$sstr=$_POST['search_input_field'];

		$dataProviderConv=$this->loadconv($sstr);

          $this->renderPartial('_ajaxContent', array(

                'dataProviderConv'=>$dataProviderConv,

        )

		, false, true) ; 

    }

view index.php


	<?php 

		echo CHtml::textField(

			'search_input_field',

			'start typing to filter...',

			array(

				'id'=>'search_input',

				'class'=>"searchbox_text_tt",

				 'onkeyup'=>CHtml::ajax(

				array(

						'type'=>'POST',

						//'url'=>'http://localhost/yiiapp/conv/UpdateAjax',

						'url'=> Yii::app()->createUrl('conv/UpdateAjax'),

						'update'=>'#data',

						'data'=>'js:jQuery(this).serialize()'

					)

				), 

				

				'onblur'=>"if (this.value == '') {this.value = 'start typing to filter...';}",

				'onfocus'=>"if (this.value == 'start typing to filter...') {this.value = '';}",

			)

		);

		?>


<div id="data" style='clear:both;'>

<?php 

$this->renderPartial('_ajaxContent', array(

	'dataProviderConv'=>$dataProviderConv,

	)); 

?>

</div>

_ajaxContent.php


<?php 

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

	'dataProvider'=>$dataProviderConv,

	'itemView'=>'_convview',

	'enableSorting'=>true,

	'ajaxUpdate' => true,

	'template'=>"{items}\n{pager}", //this remove: Displaying #... of ... result

	'cssFile'=> Yii::app()->theme->baseUrl.'/style.css',

	//'header'=>'',

	

	'pager' => array(

                'header' => '',

        ),  


));  


?>

_convview.php




	<?php echo CHtml::encode($data->id); ?>



So. why does pagination css work fine, but links in pagination don’t ?

Hi there,

Can anyon ewho has resolved this throw some light on this. I am stuck on the same problem, where once I load the CListView in the JUI.tab component, the pagination works inappropriately, with the page being loaded in the new page(and not the ajax call).

Is it a known issue?

I have similar problem. I have CTabView widget and inside CListViev render via ajax. Pagination in CListViev call to ajax function and update content which default id is "yw0". My CTabView has the same id "yw0" and when I click pagination links, then update "yw0" so my CTabView disapear and no render page.css. I change id property in CListView and now all works fine.