load and init cgridview by ajax ?


I’m Loading a CGridView by Ajax in Jquery Tabs

so the content is filled by ajax

but I think this is the reason why the ajax pagination features don’t work

probably the ajax features aren’t intialised ?

anyone have a solution ?

when I test the same gridview in normally loaded page it works fine

a similar example would be calling a cgridview inside a dialog popin

I put this into a ajax called dialog

and pagination or search wont work with ajax links

it’s always a page reload


$model=new Comments('search');


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


	'dataProvider' => $model->search(),



	'rowCssClass' => array('w','g'),









)); ?>

any hint would be greatly appreciated


anyone around ?

is it christmas holidays at Yii !!

Merry Yiistmas to all :)

I’d just like to know is it my implementation that is is wrong and someone

has this working fine

or is it just a cgridview limitation ?


I’m not sure but try setting the fourth parameter of renderPartial to true in your controller. If you have problems with AJAX features loaded by an ajax request itself, it is often the fourth parameter which makes it working.

Merry Yiistmas

Thx Kokomo

That was my Yiistmas gift of the day !!



Hi All

I added the fourth param of rendePartial to true

but in time I noticed some strange behaviors in the site

and I noticed this , renews a GET of JQuery

but seems to be breaking all the previously loaded libraries ?

can anyone confirm this ?

or explain what exactly is done when this 4th param is at true ?

I tried adding the scripts manuely (without the register Script) but then the build in features don’t work anymore

I’d be really glad to have someone elses insight on this


You just need also stop the jquery initialization twice.

Something like this:


		->scriptMap = array(

		                 'jquery.js' => false, 

                                 'jquery-ui.min.js' => false


Thanks Sysprog

but where would you put this

I tried disabling the script in the Cgrids registerScript

but that didn’t solve it

I’d like to try your way but can’t see how to implement it ?

if anyone has an idea on how to solve this

I’m getting desperate :(

You should put this into the view

that you render with the renderPartial before any jquery initializations called

I tried that but had no impact

The RenderPArtial view is loaded on demand after initial page load

but one that demand when the view is loaded

everything goes well

but when I try to access something using the initial feature libraries

these don’t work anymore

so the impact is definitly coming from the renderPartial load

but It’s a bit hard to debug and to know what is causing the problem

This is usual problem when your libraries initialized twice

  1. You need to render the main page with the all needed libraries first

  2. You can call the renderPartial (…, …, false, true) view with the forth param is on

(all libraries of the view would be loaded)

  1. You could stop the scripts initialized twice - like jquery.js or any other you need. To do this use the script above.

If any problems, try the Firebug (http://getfirebug.com/) first to see the scripts loading with the page, then, please, put the code of the main view here.

The impacting issue behind my problem is the way registerScript works

I’m not sure I’m in full control with it yet, nore how it is supposed to behave

in ajax contexts, where libs are often loaded on demand.

In this use case while desperatly trying to gain control over loading libs (when having a cgrid in a an ajax called tab)

I’m trying to only do the init part

but how to do the equivelant manuelly ?


but this keeps loading (and overloading) jquery.js again

eventhough it is allready loaded initialy

Im loading bbq and ygridview JS files manuelly (without registerScript)

but I’m stuck at trying to initialise the JS feature behind a Cgrid

could someone please give me a light on how this works ?

the solution was out there under the carpet

Thanks for great sharing Community :)


it seemed to be a clientscript bug , so I confrim it is still around ,

and I 'm quite surprised Yii didn’t integrate zaccarias solution

I prefered doing all the JS manuelly

1 - got the cgridview working in my ajax content

2 - noticed pagination and other filter ajax features were broken

3 - overloaded CgridView with a CgridViewBis where I change the registerClientScript by emptying it

4 - I now add into my ajax content the two needed scrtipt tags (jquery.yiigridview,jquery.ba-bbq) and had copied the init generated code from step 2

// initializing CGrid's ajax features  

$('#<?php echo $gridId?>').yiiGridView({'ajaxUpdate':['1','<?php echo $gridId?>'],								  'ajaxVar':'ajax',							  'pagerClass':'pager',						  'loadingClass':'grid-view-loading',							  'filterClass':'filters',							  'tableClass':'round-table',								  'selectableRows':1,							  'pageVar':'Meetings_page'});