:: Forum >>

setCellLink( ) and how can I register an onclick fuction to my link

Follow examples/quickref/grid.htm, there is the way to set the 1st column to links.

obj.setCellLink("http://www.google.com", 1); // set data
    obj.setCellTemplate(new AW.Templates.Link, 1); // and template


My question is how to set a javascript function that gets called when the link is clicked.

I have searched the source code and could not find setCellLink() method anywhere. I am a little puzzled.
Joe
Tuesday, December 6, 2005

In Code, AW has an interesting model for defining methods(functions pertaining to an object).. As we can see, methods have set and get prefixes. The model implements $get and $set collections with the corresponding functionality name. So you won't actually find 'setCellLink' in the source code for the function definition. Another advantage for this model is that if you see a 'getSomething' function you will probably also have a corresponding 'setSomething' function and vice versa. The only drawback is that the stack count becomes higher (But this is what we do with every module programming), keeping in mind that JS is a 'scripting' language after all (it is interpreted everytime, so less faster than a typical programming language. FACT: The interpretation process is actually executed by a compiled code)


Also i see that most methods have support to accept a function reference instead of a static string. So your code becomes for more flexibility:

obj.setCellLink(function(i, j){ return "http://www.mysite.com?i="+i+"&j="+j; }, 1); // set data

obj.setCellTemplate(new AW.Templates.Link, 1); // and template


To call a function simple use the 'javascript:' prefix

obj.setCellLink(function(i, j){ return "javascript: myFunction("+i+","+j+")"; }, 1); // set data

obj.setCellTemplate(new AW.Templates.Link, 1); // and template


But make sure that myFunction doesnot return any value.. otherwise the page loads a new document with result in place.

Another possibility (may be the correct) way is to set onclick event handlers for these cells and call the function you want.

Hope this helps

Sheriff
Md. Sheriff, Drivestream
Tuesday, December 13, 2005
Joe,

Here is a better way:

obj.setCellLink("javascript:void(0);", 0);

var lnk=new AW.Templates.Link;
lnk.setEvent("onclick", onLinkClick);

obj.setCellTemplate(lnk, 0);



function onLinkClick(ev){
var element=ev.srcElement || ev.target;
....
return (ev.returnValue=false);
}


you can also use the obj.onControlClicked event handler and set it to your desired function.

Cheers
Md. Sheriff, Drivestream
Wednesday, December 14, 2005
Md. Sheriff,
How I can do to get the value of the cell where I put the link ??
Thank you..
Leandro
Wednesday, December 14, 2005
Here i found another way...

obj.setCellLink("javascript:void(1);", 1);
obj.setCellTemplate(new AW.Templates.Link, 1); // and template
obj.onCellClicked = function(event, col, row){if (col==1 ) alert( this.getCellText(col, row));};


Cheers
Leandro
Wednesday, December 14, 2005
Thanks for all the answers. You guys are great.
Joe
Wednesday, December 14, 2005

This topic is archived.


Back to support forum

Forum search