3.2.0

Double click event?

Hi,

Is there a double click event? If not, how can I add one.

Thanks!

Ron
March 3,

Here's an example that assumes you have a form named "someForm" with a text field named "someInput", and you want the value of the first column to be transferred into the text field.

First you create a function that you are going to register with rows on the grid. This function needs to accept a single parameter that will be passed by the grid when it is called. In this example, the parameter is named 'src'.

function myFunction (src) {
     /* get the current grid index which is a property of src
      */
     var index=src.getProperty("item/index");

     /* use this index to find the value you want from the
      * data array you used to create the grid
      */
     document.someForm.someInput.value=myData[index]['1'];
   }


On order to trigger the function on a DoubleClick, you need to create a row template - an instruction set for all rows in the table - and tell it to respond to 'onclick' events by triggering some action defined within its parent grid.

Then, you need to add the row template to your grid, and finally, create an action in the grid that will call your function.

/* create a new row, and tell it that you will need
    * to perform some action that will exit in the grid
    */
   var row = new Active.Templates.Row;
   row.setEvent("ondblclick", function(){this.action("myAction")});

   /* add the row template to the grid
    * to perform some action that will exit in the grid
    */
   obj.setTemplate("row", row);
   obj.setAction("myAction", myFunction);


Note that I copied this code from another example I found on this site, and use regularly.
Christian (siliconbrits)
March 4,
Thanks for the response Christian!

It works great on its own.
However when I have both a click event and a dblclick event, it seems to pick up the click event instead of the dblclick event for the majority of the time.
Anybody have this problem?


Ron
March 9,
It actually tries to fire both events.
I had an alert in the event handler code for the single click event, so it delayed the second mouse click and thus the double click event never got fired.
In an attempt to solve this problem, I tried this:

var isDoubleClickEvent;

var clickAction = function(src) {
isDoubleClickEvent = false;
setTimeout(performClickAction, 500, src);
}

var performClickAction = function(src) {
if (!isDoubleClickEvent) {
// My single click event handler code
..
..
}
}

var doubleClickAction = function(src) {
isDoubleClickEvent = true;
// My double click event handler code
..
..
}

var row = new Active.Templates.Row;
row.setEvent("onClick", function(){this.action("myClickAction");
row.setEvent("ondblclick", function(){this.action("myDoubleClickAction")});
obj.setTemplate("row", row);
obj.setAction("myClickAction", clickAction);
obj.setAction("myDoubleClickAction", doubleClickAction);

Essentially the single click event handler gives the double click event a chance to fire before invoking the the single click event handler code.

However, the setTimeout() javascript function doesn't seem to like the 3rd parameter which is suppose to be the argument injected into the delayed function (in this case performClickAction). If I put a string as the 3rd parameter, I get into the clickAction() okay.

Any ideas?

Thanks!

Ron
March 10,
That work for IE but not for FIREFOX?
Daok
March 26,
It didn't work for either browsers. I thought this would work in IE.
It seems the setTimeout() function doesn't like javascript objects as the 3rd parameter.
Ron
March 29,
hi,
How can I select multiple rows under same grid id/row id using onclick event. can any one tell suggession for my problem?
satish
April 26,
Well, i have doible click event working just fine using IE

var row = obj.getTemplate("row");
row.setEvent("ondblclick", function(){this.action("myAction")});
obj.setAction("myAction", function(src){performDblClick()});

As per the comments posted on this thread, I have not found any issue with the click event clashing with the double click event.

As for selecting, mutliplt rows..first you need to make sure multiple selection is allowed on the grid by calling:

// allow multiple selection
obj.setSelectionProperty("multiple", true);

Not sure I follow ur comment about using the onclick event to multi- select rows. Can you explain in more detail what you are trying to accomplish
GuiBuilder
April 26,
just FYI - a single click always fires on a dblclick event - thats by design - because one it receives the first click - it has no way of knowing if a second one is coming or not, and each end user can set their own double click time limit on their computer - (or in otherwords if it didnt work like that - we would have something else to be really going insane over trying to figure out whats wrong on the end users machine)


If you do not notice the click event it is because either you doubleclick and are gone before you notice it, or the doubleclick overrides/overpowers it - or - what you can do is set a timeout for 200-300 milliseconds on your onclick event, to ensure more or less that a double click is not coming.
Zach
May 25,
Odd - when I define a handler it *always* fires once under Firefox when loading the page but then I cannot get it to fire again.
July 6,
I tried to use single 'onclick' to do 'dblclick' from a list.
I can't make the function finds, nor shows, the row that's clicked. Can anyone help? many thanks....
---------------------------------------------
....
function showInfo(){
var i= model.getProperty(\"index\");
obj.setSelectionIndex(i);
var rowid = obj.getDataText(i, 1);
parent.Rptframe.location.href='/cgi-bin/MyReport.cgi?id='+rowid;
}

var myData = $myData;
var cols = ['Type', 'ID', 'Name', 'Status', 'Region'];
var row = new Active.Templates.Row;
//row.setEvent(\'onclick\',\"showInfo()\");
row.setEvent(\"ondblclick\",\"showInfo()\");
....

Did I do anything wrong?
B Y
October 18,
Well, to make preious story short: how do I get row index for a single click event.(I know what double click does:
var i= model.getProperty("index"); )
B Y
October 18,

This topic is archived.

See also:


Back to support forum