CGridVew right click

Hi Yii,

So I know that CGridView has a “SelectionChanged” attribute that can return the clicked row, but this doesn’t seem to listen for a right click action.

Is there any way to do this without having to create a new JS function? And if so, how do I call the new JS function on the rows?

Thank you

You are definitely going to have to listen to click events with JavaScript, and filter out only clicks with the right mouse button. CGridView can’t do what you want out of the box.

Here is a post explaining how to make the whole row clickable with JS:

http://www.yiiframework.com/forum/index.php?/topic/15672-reacting-on-click-anywhere-in-cgridviews-row/page__p__77771__hl__cgridview+onclick#entry77771

It should get you pointed in the right direction.

So I have tried this and it gets the right primary key when i put the event.keyCode == 0. But when I changed it to event.keyCode == 2 for the right click it just brings up the regular context menu.

Here is my widget being called in the view:


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

		'id'=>'recruits-grid',

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

		'filter'=>$model,

                'selectableRows'=>'1',

                'selectionChanged'=>'userClicks',



Here is the javascript:


<script type="text/javascript">

function userClicks(target_id) {

    if(event.keyCode == 0)

    {

       alert($.fn.yiiGridView.getSelection(target_id));     

    }

}

</script>