public class SelectPicklistClass {
public static String selectedValue{get;set;}
public static List<Account> accList{get;set;}
public SelectPicklistClass(ApexPages.StandardController stdCon)
{
accList=new List<Account>();
}
public static void DisplayRecords()
{
accList=[select id,name,rating from Account where rating=:selectedValue];
}
}
Please check the below code:
vf page:
Apex Class:
Thanks
Hope this will be useful.
Below Sample Code can fulfill your requirements, Hope this will work for you.
Component :
<aura:component controller="ShowAccounts" access="global">
<aura:attribute name="AccountList" type="list[]" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
<div class="slds-truncate" title="Account Name">Account Name</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Contact">Contact</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Opportunity">Opportunity</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.AccountList}" var="acc" >
<tr>
<td data-label="Account Name">
<div class="slds-truncate" title="Cloudhub">{!acc.Name}</div>
</td>
<td data-label="Contact">
<ui:inputSelect class="slds-select" aura:id="contactID">
<ui:inputSelectOption text="" label="Please Select a contact" disabled="true" />
<aura:iteration items="{!acc.Contacts}" var="cont">
<ui:inputSelectOption text="{!cont.Id}" label="{!cont.Name}" />
</aura:iteration>
</ui:inputSelect>
</td>
<td data-label="Opportunity">
<ui:inputSelect class="slds-select" aura:id="opportunityID">
<ui:inputSelectOption text="" label="Please Select an Opportunity" disabled="true" />
<aura:iteration items="{!acc.Opportunities}" var="opp">
<ui:inputSelectOption text="{!opp.Id}" label="{!opp.Name}" />
</aura:iteration>
</ui:inputSelect>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
controller :
({
doInit : function(c, e, h) {
h.doInit_Helper(c, e, h);
},
})
Helper :
({
doInit_Helper : function(c, e, h) {
try {
var action = c.get("c.getAllAccounts");
action.setCallback(this, function(response){
var state = response.getState();
if(state === 'SUCCESS'){
var res = response.getReturnValue();
console.log('res-->>>'+res);
if(res != null) {
c.set("v.AccountList", res);
}
}else if (state === 'ERROR'){
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}else{
console.log('Something went wrong, Please check with your admin');
}
});
$A.enqueueAction(action);
} catch(ex){
console.log(ex);
}
},
})
Class :
Please mark this as best answer if this solves your problem.
Thank you,
Ajay Dubedi