+ Start a Discussion
sumit suwalkasumit suwalka 

custom lightning component like related list

 HI All,
 i created a lightning component in which i am using lightning data table and showing records of custom object.
 my component and controller is given below:-
 <aura:component controller="FBGFamilyController"
                access="global" >
    <aura:attribute name="PageHeading" type="String" default="Remove  False positive On Click Of Check Box" />
    <aura:attribute name="mydata" type="Object"/>
    <aura:attribute name="mycolumns" type="List"/>

    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    <div class="slds-m-top--xx-large">
        <div class="slds-page-header">
            <div class="slds-align--absolute-center">
                <div class="slds-text-heading--large">       

    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title slds-theme_shade">
              <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Family Records</span>

        <lightning:datatable data="{! v.mydata }" 
                             columns="{! v.mycolumns }" 
                             onrowselection="{! c.removeRow }"
controller is given below:-
    doinit : function(component, event, helper) {
        component.set('v.mycolumns', [
            {label: 'Record Number', fieldName: 'Name', type: 'integer'},
            {label: 'Sister Account', fieldName: 's1', type: 'text'},
            {label: 'Sister Account', fieldName: 's2', type: 'text'}

        var action = component.get('c.fetchRecords');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                 for (var i = 0; i < allValues.length; i++) {
                    var row = allValues[i];
                    row.s1 = row.Sister_Company__r.Name;
                 for (var i = 0; i < allValues.length; i++) {
                    var row = allValues[i];
                    row.s2 = row.Sister_Company2__r.Name;
                console.log("allValues--->>> " + allValues);
                component.set('v.mydata', allValues);
            else if(state === "ERROR") {
                var errors = response.getError();
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    console.log("Unknown Error");
    removeRow : function(component, event, helper){
        var selRows = event.getParam('selectedRows');
        // Remove the record from the table
        var rows = component.get('v.mydata');
        for (var i = 0; i<selRows.length; i++){    
            var rowIndex = rows.indexOf(selRows[i]);
            console.log('rowIndex---->>> ' + rowIndex);
            var r=rows.splice(rowIndex, 1);   
            console.log('rrr---->>> ' + JSON.stringify(r));
            component.set('v.mydata', rows);
right now its looking like this:-User-added image

i want that it should look like this standard related list given below:-
User-added imagehow can i modify my code to achive this?
Any suggestions?
Check this - http://www.infallibletechie.com/2019/03/reusable-related-list-lightning.html