I want to clear the inputtext used to search, and clear all search results using a commandbutton. I tried the following on the 'Reset' button I added but it only clears the inputtext and the search results are not clearing.
<apex:pageBlockSectionItem >
<apex:outputPanel layout="block" Rendered="true">
<apex:inputText value="{!ReportSearchString}" />
<apex:commandButton value="Search" action="{!searchReports}" reRender="ReportSearchResults, "/>
<apex:commandButton value="Back" action="{!BackToCreateFeedPage}"/>
<apex:commandButton value="Reset" onclick="this.form.reset();return false;"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection id="ReportSearchResults">
<apex:outputText value="{!warningMessage}" rendered="{!!showTable}" />
<apex:pageBlockTable value="{!reportList}" var="item" rendered="{!showTable}">
<apex:column headerValue="Report Name" >
<apex:commandLink value="{!item.Name}" action="{!BackToCreateFeedPage}">
<apex:param value="{!item.Id}" name="SelectedReport" assignTo="{!selectedReportId}" />
</apex:commandLink>
This is my search function, it works fine. I need to clear the results of this search on clicking 'Reset' button.
public void searchReports()
{
showTable = false;
reportList = new List<Report>();
reportSearchResult = new Map<Id, Report>();
selectedReport = new Report();
if((ReportSearchString != null && ReportSearchString != '') && ReportSearchString.length() >= 3)
{
reportSearchResult = new Map<Id, Report>([Select Id, Name From Report Where Name Like :'%'+ReportSearchString+'%' limit 2000]);
warningMessage = 'No Result Found';
}
else
{
warningMessage = 'Search text should have atleast 3 characters';
}
}
Best Answer
Page: have a id on first
outputpanel
andpageblocktable
and rerender them after resetting the search string and search results.Controller: