Skip to main content
how to hide showrecords button after clicking it in visualforce page?after click of button :

 

User-added imagei want to hide show records button and display only the hide table section.

 

Code:

 

<apex:page standardController="Account" extensions="TestClass">  

 

    <apex:form >

 

        <apex:outputPanel id="A2">

 

            <apex:pageBlock >

 

                <apex:pageBlockButtons location="Top" >

 

                    <apex:commandButton value="showRecords" action="{!showRecords}" reRender="A1" />

 

                </apex:pageBlockButtons>

 

            </apex:pageBlock>

 

        </apex:outputPanel>

 

        <apex:outputPanel id="A1"  >  

 

            <apex:pageBlock rendered="{!x}">

 

                <apex:pageBlockSection >

 

                    <apex:outputText > Total no of Records :{!CountOfRecords} </apex:outputText>     

 

                </apex:pageBlockSection>

 

                <apex:pageBlockTable value="{!AccList}" var="a">

 

                    <apex:column value="{!a.id}" />

 

                    <apex:column value="{!a.name}"/>

 

                    <apex:column value="{!a.industry}"/>

 

                    <apex:column value="{!a.Rating}"/>

 

                    <apex:column value="{!a.Billingcity}"/> 

 

                </apex:pageBlockTable>

 

                <apex:pageBlockButtons location="Top" >

 

                    <apex:commandButton value="HideTable" rendered="{!x}"  />  

 

                </apex:pageBlockButtons>

 

            </apex:pageBlock>

 

        </apex:outputPanel>

 

        

 

    </apex:form> 

 

</apex:page>

 

 
7 件の回答
  1. 2020年8月25日 10:51
    Hi yeshwant,

     

    Here is working code

     

    VF Page:

     

    <apex:page standardController="Account" extensions="TestClass">  

     

        <apex:form >

     

            <apex:outputPanel id="A2">

     

                <apex:pageBlock>

     

                    <apex:pageBlockButtons location="Top" >

     

                        <apex:commandButton value="showRecords" action="{!showRecords}" rendered ="{!y}" />

     

                    </apex:pageBlockButtons>

     

                </apex:pageBlock>

     

            </apex:outputPanel>

     

            <apex:outputPanel id="A1"  >  

     

                <apex:pageBlock rendered="{!x}">

     

                    <apex:pageBlockSection >

     

                        <apex:outputText > Total no of Records :{!CountOfRecords} </apex:outputText>     

     

                    </apex:pageBlockSection>

     

                    <apex:pageBlockTable value="{!AccList}" var="a">

     

                        <apex:column value="{!a.id}" />

     

                        <apex:column value="{!a.name}"/>

     

                        <apex:column value="{!a.industry}"/>

     

                        <apex:column value="{!a.Rating}"/>

     

                        <apex:column value="{!a.Billingcity}"/> 

     

                    </apex:pageBlockTable>

     

                    <apex:pageBlockButtons location="Top" >

     

                        <apex:commandButton value="HideTable" rendered="{!x}"  />  

     

                    </apex:pageBlockButtons>

     

                </apex:pageBlock>

     

            </apex:outputPanel>        

     

        </apex:form> 

     

    </apex:page>

     

    Apex class:

     

    public class TestClass {

     

        public List<account> accList {get;set;}

     

        public boolean x {get;set;}

     

        public boolean y {get;set;}

     

        public Integer CountOfRecords{get;set;}

     

        //public string city  = 'hyderabad';

     

        public TestClass(apexpages.StandardController ctrl)

     

        {

     

             y= true;

     

            accList = new List<Account>();

     

            //accList = [select id, name, phone , industry, Rating, BillingCity from Account limit 10]; 

     

        }

     

        public void showRecords()

     

        {

     

            x =true;

     

            y= false;

     

            accList = [select id, name, phone , industry, Rating,BillingCity from Account limit 10];

     

            CountOfRecords = [select count() from Account limit 10];

     

        }

     

    }

     

    Note:I have updated query for testing in my dev,Please have them corrected.

     

    Mark this as best answer.

     

    Thanks in advance.
0/9000