CGridView not working with new layout

Hi All,

I have changed the layout from the default to my own and now my ajax based CGridView filtering won’t work. Any ideas why? If I switch back to the default layout it works fine but with my own layout the relevant files are not loading up so I get this JS error:

jQuery("#surah-grid").yiiGridView is not a function

How do I make sure that the right files get loaded?

Thanks

Ziad

has the jquery.js been loaded yet?

As Davidhhuan said,

Review your main layout and double check whether you have registered the js files required -review with your old layout

Hi Guys,

Thanks for your responses. The problem was that the jquery.js was being loaded twice. Once by yii and once from google from my template (layout). I removed the google jquery and the gridview works fine but now the jquery file is not being loaded on one of my own pages (i.e. not generated by yii) and that page is completely broken.

How do I actually load the jquery file? I can’t seem to figure this out at all. I’ve looked at the controller and the view file for the page which has the gridview (where the jquery is loaded) and just can’t figure out how its being included but on my page its not being included. I must admit I do find Yii somewhat frustrating because things don’t seem to be very intuative. Am I right in saying this? I do like Yii but I’m having second thoughts about using Yii because I don’t think the documentation is great but at least if you can figure things out then its OK but I keep finding that I just can’t figure out how things are working, its just magic!

Thanks and sorry for the moan! :)

p.s. btw how do i change the number of rows that show up on the gridview from the default 10 items to something higher? Again I couldn’t find this info in the docs.

Oh another quick question: how do I load jquery from google instead of the normal one?

You need to use your scriptMap…

Here is how to do it: http://www.yiiframework.com/doc/guide/1.1/en/topics.performance#minimizing-script-files

Best

Hi Antonio,

Thanks for your help. I’m gona add jquery.js directly into my layout from google and tell yii to not load jquery.js. Do you know how to do this using the application configuration? The link you sent mentions that you can do it through the configuration but it didn’t say how. I think I really need to get my head around how the application configuration works.

Hi ziad, yes it does, read till the end:

$cs=Yii::app()->clientScript;

$cs->scriptMap=array(

'jquery.js'=>false,


'jquery.ajaxqueue.js'=>false,


'jquery.metadata.js'=>false,


......

);

<head>

<?php echo CGoogleApi::init(); ?>

<?php echo CHtml::script(

CGoogleApi::load('jquery','1.3.2') . &quot;&#092;n&quot; .


CGoogleApi::load('jquery.ajaxqueue.js') . &quot;&#092;n&quot; .


CGoogleApi::load('jquery.metadata.js')

); ?>

</head>

Hi Antonio,

Thanks again. I was actually referring to how to do this via the application configuration and that page does not exactly tell you how to do it although I admit, its pretty much there. I added the following to the components array in main.php (application configuration) to make this work. Maybe this is what you were referring to but it wasn’t clear to me. Thanks.




'clientScript' => array(

	'scriptMap' => array(

		'jquery.js' => false,

		'jquery.ajaxqueue.js'=>false,

		'jquery.metadata.js'=>false,

	),

),



Sorry Ziad, I thought you were referring to the main layout all the time.

I am glad it worked for you

Hi Antonio,

You are right I was referring to the main layout for most of the question. It’s only at the end that I was referring to the application configuration main.php so your answers were very useful so I appreciate your help.

Thanks

Ziad