How can I put a link in a GridView header? I can't seem to fully load the linked to page.

I am trying to put a link in a gridview’s header. I’ve tried several things, but in its simplest form, the following does not work:




    'header'=>CHtml::link('test', array('user/create')),


The link is displayed in the view, but does not fully load the given url when clicked.

I am using: yii-1.1.10.r3566 with wamp & chrome

Sorry if this is the wrong place to ask or if the topics been answered. Any help would be appreciated,


Hi cnorris, welcome to the forum.

I have also confirmed the symptom.





was enough to reproduce the problem.

Clicking on it caused the grid to try to update itself via ajax.

Probably the javascript for the grid (jquery.yiigridview.js) is capturing the click event on the links to implement the ajax sorting.

I’m afraid it’s rather difficult to work around this problem.

One thing I can think of is using a button instead of a link.

And I think you may also report it as an issue.

Thanks, I have created a new issue (for the first time) here:

issue 803 (I can’t embed links yet)

Thanks for the help!


I think it can be fixed by some javascript.

First add some id to your link.

Than write some javascript that will unbind "click" event on this link.

You may have right that yiigridview.js set "click" event that send ajax request.

I can’t test it now so you could try this.

I never had a problem with it, but I’m setting the type to ‘raw’:

'type' => 'raw',

My Javascript is only so-so, but I tried the following:

 Yii::app()->clientScript->registerScript(__CLASS__, "




 'header' => CHtml::link("test",array("user/create"), array('id'=>'test1')),

but I’m having the same issue.

I also tried .unbind(); and fiddled around with the CCLientScript::POS_* but nothing seems to work.

Any tips?

I don’t believe, or at least don’t know how to set ‘type’=>‘raw’, for a header?

Making it a linkButton gets the job done.

Nice. :)