Skip to main content
added 278 characters in body
Source Link
Keith C
  • 137.3k
  • 29
  • 218
  • 458

By passing this to the JavaScript, the JavaScript has a reference to the DOM element that was clicked on:

<apex:page standardController="Contact" recordSetVar="cs">
<apex:pageBlock>
<apex:pageBlockTable onRowClick="handler(this);" value="{!cs}" var="c">
    <apex:column value="{!c.Name}"/>
    <apex:column value="{!c.Birthdate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<script>
function handler(tr) {
    alert(tr.tagName);
}
</script>
</apex:page>

and can then use raw DOM processing or jQuery to generate the required output or other logic.

The above answer is to the original question which did not include the part about passing the data to the controller. A way to do that is to call the JavaScript generated by an apex:actionFunction from the handler which in turn calls a controller method passing say the ID of the clicked row.

By passing this to the JavaScript, the JavaScript has a reference to the DOM element that was clicked on:

<apex:page standardController="Contact" recordSetVar="cs">
<apex:pageBlock>
<apex:pageBlockTable onRowClick="handler(this);" value="{!cs}" var="c">
    <apex:column value="{!c.Name}"/>
    <apex:column value="{!c.Birthdate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<script>
function handler(tr) {
    alert(tr.tagName);
}
</script>
</apex:page>

and can then use raw DOM processing or jQuery to generate the required output or other logic.

The above answer is to the original question which did not include the part about passing the data to the controller.

By passing this to the JavaScript, the JavaScript has a reference to the DOM element that was clicked on:

<apex:page standardController="Contact" recordSetVar="cs">
<apex:pageBlock>
<apex:pageBlockTable onRowClick="handler(this);" value="{!cs}" var="c">
    <apex:column value="{!c.Name}"/>
    <apex:column value="{!c.Birthdate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<script>
function handler(tr) {
    alert(tr.tagName);
}
</script>
</apex:page>

and can then use raw DOM processing or jQuery to generate the required output or other logic.

The above answer is to the original question which did not include the part about passing the data to the controller. A way to do that is to call the JavaScript generated by an apex:actionFunction from the handler which in turn calls a controller method passing say the ID of the clicked row.

Source Link
Keith C
  • 137.3k
  • 29
  • 218
  • 458

By passing this to the JavaScript, the JavaScript has a reference to the DOM element that was clicked on:

<apex:page standardController="Contact" recordSetVar="cs">
<apex:pageBlock>
<apex:pageBlockTable onRowClick="handler(this);" value="{!cs}" var="c">
    <apex:column value="{!c.Name}"/>
    <apex:column value="{!c.Birthdate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<script>
function handler(tr) {
    alert(tr.tagName);
}
</script>
</apex:page>

and can then use raw DOM processing or jQuery to generate the required output or other logic.

The above answer is to the original question which did not include the part about passing the data to the controller.