PDA

View Full Version : Attaching the same click event to multiple hyperlinks in different divs?



jason0x21
23 Feb 2010, 6:09 AM
I'm following the example code posted by jclawson in this thread: http://www.extjs.com/forum/showthread.php?t=36924 (http://www.extjs.com/forum/showthread.php?t=36924), but I'm trying to get the same callback attached to all fields in all cells of a particular column in a GridPanel.

Explaining further, this column is a "list of fields" column, so a cell in that column contains a variable length list of words. Each word should be "clickable" and I should be able to find out which word the user clicked on. Here's an example of the renderer function for that particular column in the grid.


function formatInstVal(value,p,r){
var retval = "";
var temp = value.split(" ");
retval = "<div id=\"inst2field\">";
for(var i = 0; i < temp.length; i++) { retval = retval + " <a href=\"javascript:;\">" + temp[i] + "</a>"; }
retval = retval + "</div>";
return retval;
}
Which wraps everything in the cell with a single div. In the load callback for the grid I have...


Ext.fly('inst2field').on('click',function(e,t){
fieldStore.load({params: {field: t.innerHTML}});
});
For the first (top) cell in the column, this function is called just fine. For all subsequent cells in the column, nothing happens (the function isn't called. Firebug breakpoints never fire). Is this a problem with the way I'm using the div tags, or something else?

jason0x21
26 Feb 2010, 9:06 AM
Anyone? Anyone? Bueller?

Animal
26 Feb 2010, 1:58 PM
Discussion here: http://www.extjs.com/forum/showthread.php?t=15107

I think we may get Observable Columns in an upcoming version! Woohoo!

jason0x21
3 Mar 2010, 10:57 AM
Thanks for the reply! Reading the discussion tickled my brain in the right places to allow me to get it to work. I ended up using the cellClick event, and then seeing if I could get an innerHTML (from the special renderer) from the event target. Ex:


var clickText = event.getTarget().innerHTML;

Which is still involving the renderer with HTML but appears to work fine.