Categories
Appunti

Aura Component custom record list

Component

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
                access="global"
                controller="IPM_LinkedStream">
    <aura:handler name="init" value="this" action="{!c.init}"/>
    <aura:attribute name="listViewResult" type="string[]"/>
    
 
    <aura:attribute name="title" type="String" default="Stream"/>

    <lightning:card>
        <aura:set attribute="title">
            <lightning:icon iconName="standard:data_streams" size="small" class="slds-m-right_x-small"/>
            {! v.title }
        </aura:set>
        <div class="slds">        
            <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 Stream</div></th>
                        <th scope="col"><div class="slds-truncate" title="Type">Name Project</div></th>
                        <th scope="col"><div class="slds-truncate" title="Billing State">Status</div></th>                
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.listViewResult}" var="p">
                        <tr>                    
                            <td><div class="slds-truncate" title="{!p.Name}"><a  href="{!'/one/one.app?#/sObject/'+ p.Id + '/view'}" target="_blank">{!p.Name}</a></div></td>
                            <td><div class="slds-truncate" title="{!p.INN_Project__r.Name}">{!p.INN_Project__r.Name}</div></td>
                            <td><div class="slds-truncate" title="{!p.Status__c}">{!p.Status__c}</div></td>
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
        </div>

    </lightning:card>
</aura:component>

Controlle Aura

({
	init : function(component, event, helper) {        
        var action = component.get("c.getStream");
        action.setParams({
            "recordId" : component.get("v.recordId")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var listViewResult = response.getReturnValue();
                if(listViewResult.length > 0){                    
                    component.set("v.listViewResult",listViewResult);                    
                }            } 
            else if (state === "INCOMPLETE") {
            }
                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");
                    }
                }
        });
        $A.enqueueAction(action);
    },  
})

Controlle Apex

public with sharing class IPM_LinkedStream {
    @AuraEnabled
    public static List<IPM_Project_Stream__c> getStream(String recordId) {        
        List<IPM_Project_Stream__c> lIPM_Project_Stream = [SELECT Id,Name,INN_Project__r.Name,Status__c FROM IPM_Project_Stream__c WHERE INN_Project__c = : recordId LIMIT 10];
        return lIPM_Project_Stream;
    }
}

Leave a Reply