perochak
(Amjad Mughal)
July 14, 2012, 3:09pm
1
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
mdomba
(Maurizio Domba Cerin)
July 14, 2012, 10:51pm
3
can you post your "doubleclick" processing code…
perochak
(Amjad Mughal)
July 15, 2012, 2:12am
4
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.
mdomba
(Maurizio Domba Cerin)
July 15, 2012, 5:05pm
5
One solution would be to totally eliminate the default grid selection… than you can just eliminate the "selectionChanged" method and process everything on doubleclick
perochak
(Amjad Mughal)
July 16, 2012, 7:21pm
6
Thanks mdomba,
My Problem is that I need both Single and double Click processing.
mdomba
(Maurizio Domba Cerin)
July 16, 2012, 9:14pm
7
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…
perochak
(Amjad Mughal)
July 17, 2012, 11:51am
8
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();
perochak
(Amjad Mughal)
July 28, 2012, 4:49pm
10
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();
});