CGridView CButtonColumn buton url javascript

Hi All,

I would like give a link to a button on CGridView, but url has to be php expression. How can I give link to one javascript function ?

‘buttonID’ => array(

'label'=>'...',     // text label of the button


'url'=>'...',       // a PHP expression for generating the URL of the button


'imageUrl'=>'...',  // image URL of the button. If not set or false, a text link is used


'options'=>array(...), // HTML options for the button tag


'click'=>'...',     // a JS function to be invoked when the button is clicked


'visible'=>'...',   // a PHP expression for determining whether the button is visible

)

Just make the ‘url’ => ‘#’, and then put your javascript in options:




'url' => '#',

'options' => array(

  'onclick' => 'js:alert("replace this alert with your javascript");return false;',

),



Since options is just the htmlOptions you pass to CHtml::link

Hope this is what you were after.

Actually I don’t want to give ‘#’ in a link. Because once button click, it goes top of the page.I used jquery to catch the click event. But not happy thanks

Look at the code, there is return false; mean clicking the link won’t make user jump to top of the page.

However, you are safe to have the fail-safe URL in case JS is turned off. So, having url=# is not a good idea.