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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   cnorris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-May 12

Posted 07 June 2012 - 11:01 AM

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:

 
array(
    'class'=>'CButtonColumn',
    '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,
Thanks.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 1,625
  • Joined: 16-February 11
  • Location:Japan

Posted 08 June 2012 - 03:17 AM

Hi cnorris, welcome to the forum.

I have also confirmed the symptom.

array(
    'class'=>'CButtonColumn',
    'header'=>'<a>test</a>',
)

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.
https://github.com/y...sues?state=open
0

#3 User is offline   cnorris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-May 12

Posted 08 June 2012 - 11:05 AM

Thanks, I have created a new issue (for the first time) here:
issue 803 (I can't embed links yet)

Thanks for the help!
0

#4 User is offline   Mariusz W. 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 15-December 11
  • Location:Poland/Warsaw

Posted 10 June 2012 - 04:35 AM

Hi,
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.
Posted Image
Posted Image
0

#5 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 10 June 2012 - 05:22 AM

I never had a problem with it, but I'm setting the type to 'raw':
'type' => 'raw',

"Less noise - more signal"
0

#6 User is offline   cnorris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-May 12

Posted 10 June 2012 - 11:13 AM

View PostMariusz W., on 10 June 2012 - 04:35 AM, said:

Hi,
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.


My Javascript is only so-so, but I tried the following:
 Yii::app()->clientScript->registerScript(__CLASS__, "
    $('#test1').unbind('click');
    ");

and
 '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?
0

#7 User is offline   cnorris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-May 12

Posted 10 June 2012 - 11:14 AM

View Postjacmoe, on 10 June 2012 - 05:22 AM, said:

I never had a problem with it, but I'm setting the type to 'raw':
'type' => 'raw',



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

#8 User is offline   cnorris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 12-May 12

Posted 10 June 2012 - 11:40 AM

Making it a linkButton gets the job done.
1

#9 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 1,625
  • Joined: 16-February 11
  • Location:Japan

Posted 10 June 2012 - 08:22 PM

View Postcnorris, on 10 June 2012 - 11:40 AM, said:

Making it a linkButton gets the job done.


Nice. :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users