Reacting on click anywhere in CGridView's row

I have the same Problem :-/

Hm… Seems a bit risky as there might be just a one result! :]

Figured out that simple checking for empty ID does the trick.

So line:


'selectionChanged'=>'function(id){location.href = "'.$this->createUrl('view').'?id="+$.fn.yiiGridView.getSelection(id);}',

was changed to:


'selectionChanged'=>'function(id){onGridViewSelectionChange($.fn.yiiGridView.getSelection(id))}',

and a new JavaScript function was introduced in the same view file:


Yii::app()->clientScript->registerScript('grid-view-click-handler',

'

    	function onGridViewSelectionChange(id)

    	{

            	if(id != "") location.href = "'.$this->createUrl('view').'?id=" + id;

    	}

'

, CClientScript::POS_HEAD);

Works like a charm! ;]

If it works for you… than it’s OK… but for a general solution you cannot rely on getSelection() as it can return different results depending on selectableRows…

as for the one result there is no problem… my solution checks that there is only one TD in all the table… so even if there is one result after filtering there would not be only one TD as you would have at least one column with your data and one column with the buttons…

But I think I can rely on in (if selectableRows 1) if it returns any id or an empty string and that is all I need to know…

Will it also work when filters fields are hidden?

Those fields does not have anything to do with this… they are in the THEAD… and the jQuery selector gets only children() from TBODY…

Thanks! :]

Thanks Trejder,