• lightning demo 22
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I am using a datatable to display account related info.
Here's my code.
Base.cmp

<aura:component abstract="true">
    {!v.body}
</aura:component>


BaseHelper.js

({
    callServer : function(component,method,callback,params) {
        var action = component.get(method);
        if (params) {
            action.setParams(params);
        }
        
        action.setCallback(this,function(response) {
            var state = response.getState();
            if (state === "SUCCESS") { 
                // pass returned value to callback function
                callback.call(this,response.getReturnValue());   
            } else if (state === "ERROR") {
                // generic error handler
                var errors = response.getError();
                if (errors) {
                    console.log("Errors", errors);
                    if (errors[0] && errors[0].message) {
                        throw new Error("Error" + errors[0].message);
                    }
                } else {
                    throw new Error("Unknown Error");
                }
            }
        });
        
        $A.enqueueAction(action);
    }
})

SearchAccount.cmp

<aura:component implements="flexipage:availableForAllPageTypes,
                            force:appHostable"
                extends="c:Base"
                controller="AccountSearch"
                access="global">
    
     <!--I need an attribute-->
     <aura:attribute name="searchKeyWord"
                     type="String"
                     access="global"/>
      
    <!--I also need an attribute which will have list of accounts to display-->
    <aura:attribute name="accounts"
                     type="Account[]"
                     access="global"/>
     
	<div class="slds-m-around_medium">
    <lightning:card title="Enter The Account Name To Search">
       <!--I need an lightning input text to search-->
    <lightning:input name="search" 
                     value="{!v.searchKeyWord}"
                     aura:id="searchKey"
                     type="String"/>
        
     <lightning:button variant="base"
                      label="Search" 
                      onclick="{!c.fetchAccounts}"
                      iconName="utility:search"/>
    </lightning:card>
    
    
    <!-- I need to display the datatable to show and have values in the fields-->
    <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="AccountName">Name</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Phone">Phone</div>
                </th>
                
                <th scope="col">
                    <div class="slds-truncate" title="Rating">Rating</div>
                </th>
            </tr>
        </thead>
        
        <!--table body start, 
        Iterate contact list as a <tr> 
        -->
        <tbody>
            <aura:iteration items="{!v.accounts}" 
                            var="acc">
                <tr>
                    <th scope="row">
                        <div class="slds-truncate" title="{!acc.Name}">{!acc.Name}</div>
                    </th>
                    <th scope="row">
                        <div class="slds-truncate" title="{!acc.Phone}">{!acc.Phone}</div>
                    </th>
                    <th scope="row">
                        <div class="slds-truncate" title="{!acc.Rating}">{!acc.Rating}</div>
                    </th>
                  
                </tr>
            </aura:iteration>
            
        </tbody>
        
    </table>
    </div>
  </aura:component>


SearchAccountController.js

({
    fetchAccounts : function(component,event,helper) {
        helper.queryAccounts(component,helper,'');
     
   }
})


SearchAccountHelper.js

({
    queryAccounts : function(component,helper,searchkeyword)
    {
         helper.callServer(
            component,
            "c.getAccounts",
            function(response) 
            {  
                component.set('v.accounts', response);
            }, 
            {   
                Keyword : searchkeyword
            }
        );
    }
    
})

The issue is when enter the account name and click search Button I do not see any data 

Please let me know where I am going wrong.

OLIVA
Hello
I am going through aura:Action and developed a piece of code as follows.
P1Event.evt
----------
<aura:event type="COMPONENT" 
            access="global"
            description="Event template">

</aura:event>


P1Child.cmp
-----------
<aura:component>
    
	<aura:registerEvent name="handleComponentEvent"
                                         type="c.P1Event"/>
    
   <lightning:button label="Click Here To Fire The Component Event"
                      onclick="{!c.FireComponentEvent}"
                     aura:id="button1"
                      variant="brand"/>
</aura:component>

P1ChildControlelr.js
--------------------

({
	FireComponentEvent : function(component, event, helper) {
		//only get the event name
        var evtName=component.getEvent("handleComponentEvent");
        alert(evtName);
        evtName.fire();
	}
})


P1Parent.cmp
-----------
<aura:component implements="flexipage:availableForAllPageTypes" 
                access="global">
	
    <!--Here handle the component event-->
   <aura:handler event="c:P1Event"
                 name="myEventInstance"
                 action="{!c.HandleComponent}"/>
    
  <c:P1Child aura:id="ClapButton"/>
   <c:P1Child aura:id="SoundButton"/>
   <c:P1Child aura:id="DanceButton"/>
    
</aura:component>


P1ParentController.js
---------------------
({
	HandleComponent : function(component, event,helper) {
        var buttonclicked = event.getSource().getLocalId(); //find out which button was clicked
        alert(buttonclicked);
        if (buttonclicked === 'ClapButton')
            alert("I clapped");
        else if (buttonClicked === 'jumpbutton')
            alert('I am jumping!');
        else 
            alert('I am dancing!');
		}
})

When I click the button I am not able to get the alert message.

Please help me out.

thanks
oliva
Hello
I am going through aura:Action and developed a piece of code as follows.
P1Event.evt
----------
<aura:event type="COMPONENT" 
            access="global"
            description="Event template">

</aura:event>


P1Child.cmp
-----------
<aura:component>
    
	<aura:registerEvent name="handleComponentEvent"
                                         type="c.P1Event"/>
    
   <lightning:button label="Click Here To Fire The Component Event"
                      onclick="{!c.FireComponentEvent}"
                     aura:id="button1"
                      variant="brand"/>
</aura:component>

P1ChildControlelr.js
--------------------

({
	FireComponentEvent : function(component, event, helper) {
		//only get the event name
        var evtName=component.getEvent("handleComponentEvent");
        alert(evtName);
        evtName.fire();
	}
})


P1Parent.cmp
-----------
<aura:component implements="flexipage:availableForAllPageTypes" 
                access="global">
	
    <!--Here handle the component event-->
   <aura:handler event="c:P1Event"
                 name="myEventInstance"
                 action="{!c.HandleComponent}"/>
    
  <c:P1Child aura:id="ClapButton"/>
   <c:P1Child aura:id="SoundButton"/>
   <c:P1Child aura:id="DanceButton"/>
    
</aura:component>


P1ParentController.js
---------------------
({
	HandleComponent : function(component, event,helper) {
        var buttonclicked = event.getSource().getLocalId(); //find out which button was clicked
        alert(buttonclicked);
        if (buttonclicked === 'ClapButton')
            alert("I clapped");
        else if (buttonClicked === 'jumpbutton')
            alert('I am jumping!');
        else 
            alert('I am dancing!');
		}
})

When I click the button I am not able to get the alert message.

Please help me out.

thanks
oliva