Apex Class :
public with sharing class SearchContact {
@auraEnabled
public static List<contact> getContact (string name1,string email1)
{
return [select id,Name,Email,Department from Contact where(Name =: name1 and Email =: email1)];
}
}
Component :
<aura:component controller="SearchContact">
<aura:attribute name="SearchedContact" type="Contact[]" />
<aura:attribute name="name1" type="string" />
<aura:attribute name="email1" type="string" />
<lightning:input type="string" name="input1" label="name" value="{!v.name1}" />
<lightning:input type="string" name="input2" label="email" value="{!v.email1}"/>
<lightning:button label="Search" onclick="{!c.Search}" />
<aura:iteration items="{!v.SearchedContact}" var="SearchedContactIt">
<table>
<tr>
<th>name</th><th>Email</th><th>Department</th>
</tr>
<tr>
<td>{!SearchedContactIt.Name}</td><td>{!SearchedContactIt.Email}</td>
</tr>
</table>
</aura:iteration>
</aura:component>
Controller :
({
Search : function(component, event, helper) {
var Action = component.get("c.getContact");
var N1=component.get("v.name1");
var E1=component.get("v.email1");
newExpense.setParams({
"name1":N1,
"email1":E1
});
Action.setCallback(this, function(response) {
component.set("v.SearchedContact", response.getReturnValue());
});
$A.enqueueAction(Action );
},
});
Preview :
Here's your component looks like this.
You just need to enter a name or email or both and hit the search button.
All the contact with that name and email are shown as in img.