In my code, I have 2 pageblockTable with 2 values(apex).
They are displaying data in 2 different tables. First pageblockTable displays the data based on search button after giving input. Second pageBlockTable displays data when the page loads.
My requirement is to, When I click search button the second pageblockTable old data(default) should disappear and This search data should display in the second pageblockTable.
How to achieve?
Page:
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputLabel ><B>Search</B></apex:outputLabel><BR/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Enter Aadhar card Number" for="AdharcardNumberID"/>
<apex:inputText value="{!adharcard}" id="AdharcardNumberId"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Last name" for="lastnameId"/>
<apex:inputText value="{!lastname}" id="lastnameId"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Surname" for="SurnameId"/>
<apex:inputText value="{!surname}" id="SurnameId"/>
</apex:pageBlockSectionItem>
<apex:commandButton value="Search" action="{!searchRec}" reRender="recMatch, recNotMatch"/>
<apex:outputPanel id="recMatch">
<apex:pageblockSectionItem rendered="{!Match}">
<apex:pageblockTable value="{!searchObj}" var="obj">
<apex:column value="{!obj.field1}"/>
<apex:column value="{!obj.field2}"/>
<apex:column value="{!obj.field3}"/>
<apex:column value="{!obj.field4}"/>
<apex:column value="{!obj.field5}"/>
<apex:column value="{!obj.field6}"/>
<apex:column value="{!obj.field7}"/>
<apex:column value="{!obj.field8}"/>
</apex:pageblockTable>
</apex:pageblockSectionItem>
</apex:outputPanel>
<apex:outputPanel id="recNotMatch">
<apex:pageBlockSectionItem rendered="{!NoMatch}"> Record Not Found!</apex:pageBlockSectionItem>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
<!--second PageblockTable -->
<apex:pageBlock id="tablePB">
<apex:pageBlockSection title="Obj List">
<apex:pageBlockTable value="{!Objects}" var="ob">
<apex:column headerValue="Last Name">
<apex:outputLink value="/{!vict.id}" target="_blank"><apex:outputText value="{!ob.Name}" /></apex:outputLink>
</apex:column>
<apex:column value="{!ob.field1}"/>
<apex:column value="{!ob.field1}"/>
<apex:column value="{!ob.field1}"/>
<apex:column value="{!ob.field1}"/>
<apex:column value="{!ob.field1}"/>
<apex:column value="{!ob.field1}"/>
<apex:column value="{!ob.field1}"/>
<apex:column value="{!ob.field1}"/>
</apex:pageBlockTable><BR/>
Best Answer
Here the VF page is having 3 variables that is controlling the visibility of the tables/sections: "NoMatch", "Match" and "SerchMatch". Match is used to show the table which you want to displace without search, NoMatch is used to displace record not found text msg section and SerchMatch is used to displace your search result. One you hit the search button your search method is called and performs the search. Here we are controlling the visibility controlling variables.
Please use the below VF page :
At controller use this:
}
Snap : Default screen before serach :
Snap: After search : When result found:
Snap: When record not found