Friday, May 17, 2019

Lightning:card attributes

Lightning Cards are used to form a container around a information related to single item or group of item. Lightning Cards have title,body,footer. We can make use of lightning design system helper class to style the body. The title can be simple text or another component, and is displayed in the header. The footer can be simple text or another component. "Actions" attribute is also supported with lightning card and is displayed in the header.  "Actions" are nothing but the components such as button or button icon. We can make use of attribute "iconName", the icon is displayed
in the header to the left of the title.

Sample example:


    <lightning:card title="Header Text" iconName="standard:add_contact" footer="Footer Text">

        <aura:set attribute="actions">

            <lightning:button label="New"/>


        <p class="slds-p-horizontal_small">

            Body Text




Sample Image how lightning card looks like,


Let us take a simple example to understand how we can use lightning card in real example,


<aura:component controller="searchAccountController" >

    <aura:attribute name="keywordHolder" type="string" />

    <aura:attribute name="accountList" type="list" />

    <lightning:input name="AccountSearch"  label="Enter Account Name" value="{!v.keywordHolder}"/>

    <lightning:button label="Search Account" onclick="{!c.findAccount}" />

    <div class="slds-grid slds-wrap">

    <aura:iteration var="acc" items="{!v.accountList}" >

        <div class="slds-col slds-size_1-of-4 slds-p-around_small">

    <lightning:card title="Account Information" footer="Sample footer">

        <aura:set attribute="actions">

            <lightning:button label="Show Full Details"/>


        <p class="slds-p-horizontal_small">





Javascript Controller:

findAccount : function(component, event, helper) {
        var action=component.get('c.fetchAccount');

            searchKeyWord : component.get("v.keywordHolder")
            var state=response.getState();
            var response1=response.getReturnValue();



Apex controller:

public class searchAccountController {
 public static List < account > fetchAccount(String searchKeyWord) {
  String searchKey = searchKeyWord + '%';
  List < Account > returnList = new List < Account > ();
  List < Account > lstOfAccount = [select id, Name, Type, Industry, Phone, Fax from account where Name LIKE: searchKey limit 10];

  for (Account acc: lstOfAccount) {
  return returnList;



<aura:application extends="force:slds" >




No comments:

Post a Comment