CGridView - Get id of selected row by double click

Hi,

I am facing problem in getting value of selected row using double click method of jquery.

I have following code




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

	'id'=>'messages-grid',

	'dataProvider'=>$dataProvider,

        'template'=>'{items}{pager}',

        'cssFile'=>Yii::app()->baseUrl.'/css/grid.css',

        'selectionChanged'=>'

function(id){

         id=$.fn.yiiGridView.getSelection(id);

         selected_message_id=id; // this is the value of currently selected row

}',

	'columns'=>array(

                'keyword.name',

                'title',            

	//	'scheduled_date',

                array(

                    'name'=>'scheduled_date',

                    'value'=>'$data->getScheduledDate()'

                ),

                array(

                    'name'=>'time_zone',

                    'value'=>'$data->getTimeZone()'

                ),

                array(

                    'name'=>'status',

                    'value'=>'$data->getStatusText()'

                ),

                array(

                    'name'=>'enterprise',

                    'value'=>'$data->isEnterprise()'

                ),

            		'message',

         


))); ?>  



Problem which I am facing is that on double click on the row, it deselect the row.

i.e. on clicking it first selects and then deselect and in results value of selected_message_id becomes empty/null

Is there any solution to this issue?

How about if in your function you detect the first click, grab the ID, then if its a double click you use the ID from the first click, then click() the row to reselect it?

Just a thought :slight_smile:

can you post your "doubleclick" processing code…

The code is as




$('#messages-grid').dblclick(function(){

    showMessage(); 

});



The case really is that, the Yii Grid JS script uses on click method of jquery. It does not differentiate between single and double click.

@Backslider

Dear, As I have said that when we click, it first assigns the value of the id but when we click again, it reassign value to variable which is null.

You can try to click on grid row. if you click double on a row, it will be unselected.

One solution would be to totally eliminate the default grid selection… than you can just eliminate the "selectionChanged" method and process everything on doubleclick

Thanks mdomba,

My Problem is that I need both Single and double Click processing.

Can you describe a bit more about your need for single and double click processing…

As I see this… the problem is that whenever you "doubleclick" the single click event handler will be processed two times…

My current requirement is that

On a single click, the row should be selected for further processing as I have created Buttons outside the grid and I am using the cur

I don’t believe that you understood my suggestion.

Currently you have a click event on the row. With this event, you can grab the ID so that if its a double click, you can fire your double click event and at the same time restore the row to how you want… you can simply do:




    $("#"+theIDweGrabbed).click();



Backslider, you means to say that, inside my custom function




$('#messages-grid').dblclick(function(){

    showMessage(); 

});



I should call it as


$('#messages-grid').dblclick(function(){

$("#"+selected_message_id).click();

    showMessage(); 

});