0

I've built the Lightning component which displays the paid list of invoice. While I display all the records of the invoice in Lightning Component(Both paid and overdue records), it doesn't show any empty rows. But while I try to display on the Paid list of records I'm getting the empty rows which are shown in the image. I've shared my code. Please, anyone, help me to remove these empty rows from Lightning component.

enter image description here

APEX CLASS:

    public class QuickBooksInvoice1 {

    public class invoicePaid{
      @AuraEnabled public Date ddate{get;set;} 
        @AuraEnabled public String type{get;set;} 
        @AuraEnabled public String no{get;set;}
        @AuraEnabled public String customer{get;set;}
        @AuraEnabled public Date duedate{get;set;}  
      @AuraEnabled public String balance{get;set;}
        @AuraEnabled public String total{get;set;}
         @AuraEnabled public String status{get;set;}

    }
    @AuraEnabled
    public Static List<invoicePaid> fetching(){ 

       String endpoint='XXXXXXXX';


        Http h=new Http();
        HttpRequest req=new HttpRequest();


        req.setMethod('GET');    
         req.setEndpoint(endpoint);

       req.setHeader('Accept', 'application/json');
        req.setHeader('Authorization' , ' Bearer XXXXXXXXXXXX');

        HttpResponse res=h.send(req);
        String result=res.getBody();

        System.debug('Response Body!!!!!'+result);
        System.debug(res.getStatus());
        System.debug(res.getStatusCode());


         List<Date> ddate=new List<Date>();
        String type='Invoice';
        List<String> no=new List<String>();
        List<String> customer=new List<String>();
        List<Date> duedate=new List<Date>();

        List<String> balance=new List<String>();
         List<String> total=new List<String>();
        String status;

         JSONParser parse=JSON.createParser(result);   

        while (parse.nextToken() != null) {
         if ((parse.getCurrentToken() == JSONToken.FIELD_NAME) &&
                (parse.getText() == 'TxnDate')) {

                parse.nextToken();

                ddate.add(parse.getDateValue());

                    System.debug(ddate);

            }
        }

        JSONParser parse3=JSON.createParser(result);   
        while (parse3.nextToken() != null) {
         if ((parse3.getCurrentToken() == JSONToken.FIELD_NAME) &&
                (parse3.getText() == 'name')) {

                parse3.nextToken();

               customer.add(parse3.getText());
                    System.debug(customer);
            }
        }
        JSONParser parse4=JSON.createParser(result);   
        while (parse4.nextToken() != null) {
         if ((parse4.getCurrentToken() == JSONToken.FIELD_NAME) &&
                (parse4.getText() == 'DocNumber')) {

                parse4.nextToken();

               no.add(parse4.getText());
                    System.debug(no);
            }
        }
         JSONParser parse5=JSON.createParser(result);   
        while (parse5.nextToken() != null) {
         if ((parse5.getCurrentToken() == JSONToken.FIELD_NAME) &&
                (parse5.getText() == 'DueDate')) {

                parse5.nextToken();

               duedate.add(parse5.getDateValue());
                    System.debug(duedate);


            }
        }
         JSONParser parse7=JSON.createParser(result);   
        while (parse7.nextToken() != null) {
         if ((parse7.getCurrentToken() == JSONToken.FIELD_NAME) &&
                (parse7.getText() == 'Balance')) {

                parse7.nextToken();

               balance.add(parse7.getText());
                    System.debug(balance);


            }
        }
          JSONParser parse2=JSON.createParser(result);   
        while (parse2.nextToken() != null) {
         if ((parse2.getCurrentToken() == JSONToken.FIELD_NAME) &&
                (parse2.getText() == 'TotalAmt')) {

                parse2.nextToken();

                total.add(parse2.getText());
                    System.debug(total);
            }
        }


         **List<invoicePaid> ip=new List<invoicePaid>();


        for(integer i=0;i<balance.size();i++){

          invoicePaid a=new invoicePaid();

        if(balance[i]=='0'){
            a.ddate=ddate[i];
            a.type=type;
            a.customer=customer[i];
            a.no=no[i];
            a.duedate=duedate[i];
            a.balance=balance[i];
             a.total=total[i];
                 a.status='Paid';
        }

             ip.add(a);
         }

        System.debug(ip);

        return ip;

    }**
}

LIGHTNING COMPONENT:

<aura:component controller="QuickBooksInvoice1" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

<aura:attribute name="invoice" type="List" />
<aura:attribute type="Boolean" name="sortSta" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="slds-p-around--large" >
    <div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small"><b>Invoice Paid Details</b></h3>


            </header>
    </div>

    <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="Date">Date</div></th>
                <th scope="col"><div class="slds-truncate" title="Type">Type</div></th>
                <th scope="col"><div class="slds-truncate" title="No">No.</div></th>
                <th scope="col"><div class="slds-truncate" title="Customer">Customer</div></th>
                <th scope="col"><div class="slds-truncate" title="Duedate">Due Date</div></th>

                <th scope="col"><div class="slds-truncate" title="Balance">Balance</div></th>
                <th scope="col"><div class="slds-truncate" title="Total">Total</div></th>
                <th scope="col"><div class="slds-truncate" title="Status">Status</div></th>
            </tr>
        </thead>
        <tbody>

            <aura:iteration items="{!v.invoice}" var="inv">
                <tr>
                    <th scope="row"><div class="slds-truncate" title="{!inv.ddate}">{!inv.ddate}</div></th>
                    <td><div class="slds-truncate" title="{!inv.type}">{!inv.type}</div></td>
                    <td><div class="slds-truncate" title="{!inv.no}">{!inv.no}</div></td>
                    <td><div class="slds-truncate" title="{!inv.customer}">{!inv.customer}</div></td>
                    <td><div class="slds-truncate" title="{!inv.duedate}">{!inv.duedate}</div></td>

                    <td><div class="slds-truncate" title="{!inv.balance}">{!inv.balance}</div></td>
                    <td><div class="slds-truncate" title="{!inv.total}">{!inv.total}</div></td>
                    <td><div class="slds-truncate" title="{!inv.status}">{!inv.status}</div></td>
                    <option value="{!item}">{!item}</option>
                </tr>
            </aura:iteration>
        </tbody>
    </table>
</div>

CONTROLLER CLASS:

({
    "doInit" : function(component) {
        var action = component.get("c.fetching");
        action.setParams({ init : component.get("v.invoice") });

        action.setCallback(this, function(response){
            var state = response.getState();

            console.log(response.getState());
            if (state === "SUCCESS"){
                var result = response.getReturnValue();    

                component.set("v.invoice", result);
                console.log(" Values of string!!!  ", component.set("v.invoice", result));
                console.log(" Value!!!!!! ", result);

            }
            else{
                console.log(" FAILURE ",response.getState());
            }
        });
        $A.enqueueAction(action);
    }
})

1 Answer 1

1

Here's your problem.

    for(integer i=0;i<balance.size();i++){

      invoicePaid a=new invoicePaid();

    if(balance[i]=='0'){
        a.ddate=ddate[i];
        a.type=type;
        a.customer=customer[i];
        a.no=no[i];
        a.duedate=duedate[i];
        a.balance=balance[i];
         a.total=total[i];
             a.status='Paid';
    }

         ip.add(a);
     }

Your loop here always creates an invoicePaid object and always adds it to the list to be returned to your Lightning component. But if balance[i]=='0', your code does not populate any of its values, leading to display of empty rows.

Easy fix? Move

      invoicePaid a=new invoicePaid();

and

         ip.add(a);

inside the loop.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .