Monday, September 04, 2006

Select the current row by just clicking on it (and little coding)

It took us some time to figure out how to select the current row in an ADF table by clicking on it, but in the end the solution is very simple.
  • Give your "af:tableSelectOne" an id property for instance “select_id”.
  • Give all the columns in your table an onClick property for instance: onclick="makeCurrent(this);"
  • Ad javascript to your page with yhe following code:
  • document.getElementById(tr.id.substring(0,tr.id.lastIndexOf(":")+1)+"select_id").checked=true;

Try out your page and you'll see it works. Every click on a column in your table will make the current row indead current.

What this code does is working around the ADF coding for your table columns; Adf will generate the following id for an item(inputtext1) residing in the second row in your table("tab_1") on your form ("form_1") ..............(notice: zero based index)

id="form_1:tab_1:1:inputText1"

where ":1:" stands for the current row. You cannot (or do not want to) refer to this directly because it is an automatically generated number. You do not have any control on it. By substringing the entry and then adding the "select_id" to it, you can make the current row current. Just add .checked="true"

Not much code but a lot of thinking..........

2 comments:

Jose said...

Could you please show me the whole javascript?

thanks...

luc bors said...

Hi Jose,I think that this is what you need. If you call makeCurrent(this) than the script has to use 'this'.

document.getElementById(this.id.substring(0,this.id.lastIndexOf(“:”)+1)+”select_id”).checked=true;

Get back to me if this doesn't help you. On monday I can give you the whole code sample.

Good luck.