function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kumar Santosh 17Kumar Santosh 17 

Output not Appearing

Input search text given but output was not displaying

Lightning Component
Component
Controller
ControllerApex Class
Apex ClassOutput Preview
Output
Soundar Rajan PonpandiSoundar Rajan Ponpandi
Hi Kumar,

1. Please put debug log in apex class (It's returning list of accounts or not ?)

2. Check with alert / console in controller.js (Are you getting  a return response or not) ?

3. Everything is fine from Component, So you should check in Controller.JS and Apex class only.

Please Refer the following code for accurate result.

Component
<aura:component controller="AccountsController">
    <aura:attribute name="accounts" type="List" />
    <aura:attribute name="key" type="String" /> 
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />        
    <lightning:input type="text" name="searchKey" label="Enter" aura:id="searchKey" onchange="{!c.searchKeyChange}" placeholder="Search" />          
    <table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
        <thead>
            <tr class="slds-text-heading_label">              
                <th scope="col"><div class="slds-truncate" title="Name">Name</div></th>
                <th scope="col"><div class="slds-truncate" title="Type">Type</div></th>         
                <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>            
            </tr>
        </thead>
        <tbody>
            <aura:iteration items="{!v.accounts}" var="account">
                <tr>  
                    <td><div class="slds-truncate" title="{!account.Name}">{!account.Name}</div></td>
                    <td><div class="slds-truncate" title="{!account.Type}">{!account.Type}</div></td>                   
                    <td><div class="slds-truncate" title="{!account.Phone}">{!account.Phone}</div></td>                    
                </tr>
            </aura:iteration>
        </tbody>
    </table>
</aura:component>

Controller.JS
({
    doInit: function(component, event, helper) {
        helper.getAccountList(component);
    },
    searchKeyChange: function(component, event) {
        var searchKey = component.find("searchKey").get("v.value");
        console.log('searchKey:::::'+searchKey);
        var action = component.get("c.findByName");
        action.setParams({
            "searchKey": searchKey
        });
        action.setCallback(this, function(a) {
            component.set("v.accounts", a.getReturnValue());
        });
        $A.enqueueAction(action);
    }   
})

Helper.JS
({      
    getAccountList: function(component) {
        var action = component.get('c.getAccounts');
        var self = this;
        action.setCallback(this, function(actionResult) {
            component.set('v.accounts', actionResult.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})

Apex Class
public class AccountsController {
    @AuraEnabled
    public static List <Account> getAccounts() {
        return [SELECT Id, name, Type, Phone FROM Account ORDER BY createdDate ASC];
    }    
    @AuraEnabled
    public static List<Account> findByName(String searchKey) {
        String name =  + searchKey + '%';
        return [SELECT id, name, phone,type FROM Account WHERE name LIKE :name];
    }
}

Please Mark this one as best answer if it's resolved your query.
​​​​​​​​​​​​​​​​​​​​​

Regards,
Soundar. 
Vinodraj ShivanandaVinodraj Shivananda
It is always better to first use the query in the anonymous window to check if the query you are going to use in the apex class is returning records.
You can execute something like this in the anonymous window. Use as System.debug and console.log(in js controller) to check if the records are being returned.
String search_text =  '%' + contactName + '%';
String query_string  = 'SELECT Id, Name, Email, Phone, Birthdate FROM Contact where name Like  : search_text ';
return database.query(query_string);