+ Start a Discussion

onRowClick of pageBlockTable Best Practice


I'm trying to use the onRowClick of the pageBlockTable to update a section of a page with javascript based on which row was clicked. How can I determine which row has been clicked on the onRowClick event and grab the id of the object in that row?

Thanks for any help :)

I've got a solution that's a bit of a hack. I'm not using the onRowClick event, instead I put an onclick event in each column to call the javascript.

<apex:pageBlock id="myBlock">
  <apex:pageBlockTable id="myTable" value="{!MyObjects}" var="m">
    <apex:column value="{!m.Name}" onclick="myFunction('{!m.Name}','{!m.Id}');" />
    <apex:column value="{!m.Field1__c}" onclick="myFunction('{!m.Name}','{!m.Id}');" />
    <apex:column value="{!m.Field2__c}" onclick="myFunction('{!m.Name}','{!m.Id}');" />
    <apex:column value="{!m.Field3__c}" onclick="myFunction('{!m.Name}','{!m.Id}');" />

I think it would be better if you could do something like this:

<apex:pageBlock id="myBlock">
  <apex:pageBlockTable id="myTable" value="{!MyObjects}" var="m" onRowClick="myFunction('{!m.Name}','{!m.Id}');">
    <apex:column value="{!m.Name}" />
    <apex:column value="{!m.Field1__c}" />
    <apex:column value="{!m.Field2__c}" />
    <apex:column value="{!m.Field3__c}" />

 Thanks again for any help :)

Message Edited by Scott.M on 08-12-2008 06:42 AM
Sakti Sahoo 5Sakti Sahoo 5
Hi Scott.

I refer your code and it works for me to get name and id on clicking the row.

Below is the sample code, that i used.

<apex:pageBlockTable value="{!incidents}" var="Inc" id="tbl_id" border="1" onRowClick="Test('{!Inc.name}','{!Inc.Id}')">

and in the javascript ,

function Test(name,id)
        alert("Name of the record is"+ name + "and the record id is " +id);