How to display the records based on Picklist value in visualforce
<apex:page controller="AccountController2" showHeader="false">
<apex:slds />
<apex:form id="test">
<apex:selectList size="1" style="width:10%;" value="{!selectedIndustry}" styleClass="slds-input" rendered="{!isclicked==false}">
<apex:selectOptions value="{!AccountIndPickValues}" />
</apex:selectList> <br/><br/>
<apex:commandButton value="show" rendered="{!isclicked==false}" styleClass="slds-button slds-button_brand" action="{!searchAccountRecords}" />
<apex:outputpanel rendered="{!isclicked==true}" >
<table class="slds-table" width="100%" style="margin-left:5px;">
<tr>
<td><b>S.No</b></td>
<td><b>Name</b></td>
<td><b>Site</b></td>
<td><b>AccountNumber </b></td>
<td><b>Industry</b></td>
<apex:variable value="{!0}" var="index" />
</tr>
<apex:repeat value="{!acc_list}" var="Items">
<tr>
<td>
<apex:variable value="{!index + 1}" var="index" />
{!index}
</td>
<td>
<apex:outputText value="{!Items.Name}"/>
</td>
<td>
<apex:outputText value="{!Items.Site}"/>
</td>
<td>
<apex:outputText value="{!Items.AccountNumber }"/>
</td>
<td>
<apex:outputText value="{!Items.Industry}"/>
</td>
</tr>
</apex:repeat>
</table>
</apex:outputpanel>
</apex:form>
</apex:page>
public class AccountController2
{
public string selectedIndustry{set;get;}
public List<Account> acc_list{set;get;}
public boolean isclicked{set;get;}
public AccountController2()
{
getAccountIndPickValues();
isclicked=false;
}
public List<SelectOption> getAccountIndPickValues()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
options.add(new SelectOption('','--None--'));
for(Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public void searchAccountRecords()
{
isclicked=true;
acc_list=[select Name,Site,AccountNumber,Industry from Account where Industry=:selectedIndustry];
}
}
Comments
Post a Comment