0

I am trying to add rows dynamically in my table in vf page. but when I try to do so it overlaps the current row.

here is my controller class:

public class BulkPaymentController {


public String message;    
public boolean balanceFlag = false;    
public static boolean selected {get;set;} 
public List<Invoice__c> invoiceList {get;set;}
public String selectedInv {get;set;}
public List<SelectOption>invoicess {get;set;}    

public Map<Integer,InvoiceWrapper> mapSelectInvoiceList {get; set;}

public Integer incrmnt {get;set;}

public BulkPaymentController(){
    incrmnt =0;
    balanceFlag = false;
    invoicess =new List<SelectOption>();
        invoicess.add(new SelectOption('','select'));
    for(Invoice__c inv:[select Id, Name from Invoice__c]){            
        invoicess.add(new SelectOption(inv.id,inv.Name));
    }    

    mapSelectInvoiceList = new Map<Integer,InvoiceWrapper>();
    mapSelectInvoiceList.put(incrmnt,new InvoiceWrapper(false,new Invoice__c(),invoicess));

}
public PageReference addInvoice() {

    incrmnt +=1;

    mapSelectInvoiceList.put(incrmnt,new InvoiceWrapper(false,new Invoice__c(),invoicess));

    return null;
}
public PageReference showInvoices(){        

        for(Invoice__c inv: [select Id, Name,Delivery_Order__c,Delivery_Order__r.Name,Sales_Order__c, Sales_Order__r.Name,Total_Quantity__c,Subtotal_Amount__c,
            Total_Tax_Amount__c,Total_Amount_Inc_Tax__c,Document_Number_Discount_Amount__c,Payment_Invoice_Header__c
            from Invoice__c where id =:selectedInv]) {             


            mapSelectInvoiceList.put(incrmnt,new InvoiceWrapper(false,inv,invoicess));

        }        

return null;
}
public class InvoiceWrapper{
    public List<SelectOption> invoiceslist {get;set;}
    public Boolean selected{get;set;}
    public  Invoice__c inv{get;set;}
    public InvoiceWrapper(Boolean selected1, Invoice__c inv1,List<SelectOption> invoiceslist )
    {
        selected = selected1;
        inv = inv1;
        this.invoiceslist =invoiceslist;            

    }
}
}

vf page

<apex:outputPanel id="InvoicePanel">
            <div aria-hidden="false" class="slds-section__content" id="expando-unique-id">
                <div class="slds-col slds-size_1-of-1">
                    <div class="slds-box slds-m-vertical_small">
                        <table class="slds-table slds-table_bordered slds-table_cell-buffer" id= "table">



                            <apex:repeat value="{!mapSelectInvoiceList[incrmnt]}" var="i" >
                                <tr>

                                    <th scope="row" data-label="">
                                        <div class="slds-truncate" title="">
                                            <apex:selectList value="{!selectedInv}" size="1" multiselect="false" id="selectInvoice">

                                                <apex:selectOptions value="{!i.invoiceslist}"/>
                                                 <apex:actionSupport event="onchange" action="{!showInvoices}" reRender="InvoicePanel" status="status" >

                                                 </apex:actionSupport>  
                                            </apex:selectList>

                                        </div>
                                    </th>

                                    <th scope="row" data-label="">

                                        <div class="slds-truncate" title="">
                                            <a href="/{!i.inv.Sales_Order__c}"
                                               target="_blank">{!i.inv.Sales_Order__r.Name}</a>
                                        </div>

                                    </th>
                                    <th scope="row" data-label="">

                                        <div class="slds-truncate" title="">
                                            <a href="/{!i.inv.Delivery_Order__c}"
                                               target="_blank">{!i.inv.Delivery_Order__r.Name}</a>
                                        </div>

                                    </th>
                                    <th scope="row" data-label="">

                                        <div class="slds-truncate" title="">
                                                {!i.inv.Total_Quantity__c}
                                        </div>

                                    </th>
                                    <th scope="row" data-label="">

                                        <div class="slds-truncate" title="">
                                                {!i.inv.Subtotal_Amount__c}
                                        </div>

                                    </th>
                                    <th scope="row" data-label="">

                                        <div class="slds-truncate" title="">
                                                {!i.inv.Total_Tax_Amount__c}
                                        </div>

                                    </th>
                                    <th scope="row" data-label="">

                                        <div class="slds-truncate" title="">
                                                {!i.inv.Document_Number_Discount_Amount__c}
                                        </div>

                                    </th>
                                    <th scope="row" data-label="">

                                        <div class="slds-truncate" title="">
                                                {!i.inv.Total_Amount_Inc_Tax__c}
                                        </div>

                                    </th>

                                </tr>
                            </apex:repeat>


                            </tbody>
                        </table>
                         <apex:commandButton styleClass="slds-button slds-button--neutral cuf-publisherCancelButton uiButton"
                                action="{!addInvoice}" value="Add Invoice" rerender="InvoicePanel" status="status" 
                                style="margin-top:8px;" />
                    </div>
                </div>
            </div>
        </apex:outputPanel>

    </div>

Please help me to solve this issue.

1

Use List instead of Map

mapSelectInvoiceList = new list< InvoiceWrapper >();

mapSelectInvoiceList.add(new InvoiceWrapper(false,new Invoice__c(),invoicess));

 <apex:repeat value="{!mapSelectInvoiceList}" var="i" >
</apex:repeat>

public PageReference addInvoice() {

    mapSelectInvoiceList.add(new InvoiceWrapper(false,new Invoice__c(),invoicess));

    return null;
}
  • previously I used the list but its showing duplicate value. that's why I used Map for avoiding duplicate – Hennry Jan 8 at 6:50
  • Duplicate values means ? When press the add button list add an another row with wrapper values. – gowtham Jan 8 at 7:13
  • no, when selecting any value from picklist a new row added with duplicate value like 3 times if I selected then 3 rows created with same values. – Hennry Jan 8 at 7:18
  • I cant understand your Code.When ever u change the picklist, is table should added with one row ? – gowtham Jan 8 at 9:03
  • yes, In case if i used list instead of map – Hennry Jan 8 at 9:06

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.