+ Start a Discussion

Any way to get the Row Number in a tag within a PageBlockTable?

I want a button in my page block table that calls an action method with a row number as a paramenter.  Anyone know if there's a way to refer to the row number?

  <apex:column id="myColumn">
	<apex:commandButton value="MyButtonLabel">
		<apex:param name="rowNumber" value="???"/>

Assuming that column is within a PageBlockTable What I'd like to do is put something in the ??? in the code segment above that will give me the row number, 0-n.






1. Why do you need a row number and not just use the recordID?


i know you have a reason but I just curious.....


I do not believe there is a direct access to a row number and the best way to do it would be by using a simple wrapper class to:


a. Hold your data

b. have one additional field for row

c. Sort by row number (you can fill wrapper any way you need then assign row numbers and sort)


The use that as your data set and when clicking the button return the row field.


The data is not an sObject, its a custom inner class in the controller.


I could create an artificial column and set them 0, 1, 2, as I build the list but that's a pain to maintain.  There will be options that manipulate the list moving sets of items around.  Every time that is done, I'd have to reasign  the numbers on the back end.


I can easily do it in a javascript by putting and onclick on it. The javascript can parse out the row number and call and actionFunction that assigns that to a merge variable.


It just seems there ought to be amore elegant way,.




I think this can be done using apex variable tag, you have to repeat it inside the page block table , it is just like iterating an index in the for loop .