function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tolby HuntTolby Hunt 

Visualforce PageBlockTable click to get row and then pass to apex:detail subject

Hello! I am trying to display a list of opportunities and when i click on a row of an opportunity i get the full opportunity in apex:detail below the list.

 
<apex:page standardController="Opportunity" extensions="opportunityControllerExtension" recordSetVar="opportunities" tabstyle="opportunity" sidebar="false">
<head>
<apex:includeScript value="{!URLFOR($Resource.jQuery)}"  />
<script type="text/javascript">
    $j = jQuery.noConflict();
    function clickElem(elem){
        var row = parseInt($j(elem).find(".accId").html());
        alert(row);
        $j(elem).find("myString").value = row
;
    }
</script>
<apex:variable value="{!0}" var="index" />
</head>
  <apex:pageBlock >
    <apex:form >
      <apex:panelGrid columns="9">
        <apex:outputLabel value="View:"/>
        <apex:selectList value="{!filterId}" size="1">
          <apex:actionSupport event="onchange" rerender="list"/>
          <apex:selectOptions value="{!listviewoptions}"/>
        </apex:selectList>
      </apex:panelGrid>
      <apex:pageBlockTable value="{!opportunities}" var="a" id="list" onRowClick="clickElem(this);">
        <apex:column value="{!a.name}"/>
        <apex:column value="{!a.Created_Date__c}"/>
        <apex:column value="{!a.Underwriting_Stage__c}"/>
        <apex:column value="{!a.X0_Credit_Lines_Pre_Approval_Amount__c}"/>
        <apex:column value="{!a.Total_Paydowns__c}"/>
        <apex:column value="{!a.Term_Loan_Pre_Approval_Amount__c}"/>
        <apex:column value="{!a.Date_Signed__c}"/>
        <apex:column value="{!a.Reasoning_if_Failed_Credit__c}"/>
        <apex:column styleClass="accId">
                <apex:outputText >
                <apex:variable value="{!index + 1}" var="index" />
                {!index}
                </apex:outputText>
            </apex:column>
      </apex:pageBlockTable>
    </apex:form>
    <apex:pageBlock >
        <apex:detail subject="{!opportunities[myString]}" />
    </apex:pageBlock>
  </apex:pageBlock>
</apex:page>

Any help would be appreciated!
Thanks
Best Answer chosen by Tolby Hunt
Suraj TripathiSuraj Tripathi

Hi Tolby,
Try this piece of code.
 
Visualforce page

 

<apex:page standardController="Opportunity" recordSetVar="Opportunity" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageBlock>
            <apex:pageBlockTable value="{!Opportunity}" var="a">
                <apex:column headerValue="Name" >
                    <apex:commandLink value="{!a.name}" reRender="out">
                        <apex:param name="id" value="{!a.id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column value="{!a.CloseDate}"/>
                <apex:column value="{!a.Amount}"/>
                <apex:column value="{!a.Probability}"/> 
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
    <apex:outputPanel id="out">
        <apex:detail subject="{!$CurrentPage.parameters.id}" relatedList="false" title="false"/> 
    </apex:outputPanel>
</apex:page>
Screenshot :
User-added image
User-added image

Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Regards ,
Suraj

All Answers

Suraj TripathiSuraj Tripathi

Hi Tolby,
Try this piece of code.
 
Visualforce page

 

<apex:page standardController="Opportunity" recordSetVar="Opportunity" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageBlock>
            <apex:pageBlockTable value="{!Opportunity}" var="a">
                <apex:column headerValue="Name" >
                    <apex:commandLink value="{!a.name}" reRender="out">
                        <apex:param name="id" value="{!a.id}"/>
                    </apex:commandLink>
                </apex:column>
                <apex:column value="{!a.CloseDate}"/>
                <apex:column value="{!a.Amount}"/>
                <apex:column value="{!a.Probability}"/> 
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
    <apex:outputPanel id="out">
        <apex:detail subject="{!$CurrentPage.parameters.id}" relatedList="false" title="false"/> 
    </apex:outputPanel>
</apex:page>
Screenshot :
User-added image
User-added image

Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Regards ,
Suraj
This was selected as the best answer
Suraj TripathiSuraj Tripathi
Thank you, Tolby for selecting my answer as best. It's my pleasure to help you.