0

I have 2 objects Custom_Package__c(contains static data) & RPFChild__c. I have the below vf page where i am trying to add rows dynamically. The problem i am facing is when vf page loads it displays all the records with all the fields filled up.

I want when vf page loads only 5 blank rows should appear. Then i will up the values, if needed i will add more rows(which is working). After then the values will be inserted to RPFChild__c object.

Vf Page -

<apex:page standardController="RFP__c" extensions="addRPFchild" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <style type="text/css">
      .oddrow{background-color: #00FFFF; } 
      .evenrow{background-color: #7FFFD4; }        
      .textalign{text-align:center; } 
  </style>
  <script type="text/javascript">
    function removeHighlight(elem){
        $(elem).removeClass('highlight');
    }  
  </script>
  <apex:form >
    <apex:pageBlock id="pb">
      <apex:pageMessages />
      <apex:outputText rendered="{!isRerender}">
        <style type="text/css">.last{background-color: #FF0000; }</style>
      </apex:outputText>      
      <apex:variable var="rowNumber" value="{!0}"/>
      <!--  <apex:pageblockSection columns="1"> -->
        <apex:pageBlockTable id="thetable"  var="acc" value="{!attendeeList}" rowClasses="oddrow,evenrow" onRowMouseOver="removeHighlight(this)">
          <apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext">
            <apex:outputText value="{0}" style="text-align:center;">
              <apex:param value="{!rowNumber+1}" />
            </apex:outputText>
          </apex:column>
          <apex:column headerValue="Name" >
            <apex:inputField value="{!acc.Name}"/>
          </apex:column>
          <apex:column headerValue="Market" >
            <apex:inputField value="{!acc.Market__c}"/>
          </apex:column>
          <apex:column headerValue="State" >
            <apex:inputField value="{!acc.State__c}"/>
          </apex:column>
          <apex:column headerValue="First Issue" >
            <apex:inputField value="{!acc.First_Issue__c}"/>
          </apex:column>
          <apex:column headerValue="Last Issue" >
            <apex:inputField value="{!acc.Last_Issue__c}"/>
          </apex:column>
          <apex:column headerValue="Circulation" >
            <apex:inputField value="{!acc.Circulation__c}"/>
          </apex:column>
            <apex:column headerValue="Space Unit" >
            <apex:inputField value="{!acc.Space_Unit__c }"/>
          </apex:column>
          <apex:column headerValue="Action" >
            <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb">
              <apex:param name="rowIndex" value="{!rowNumber}"/>
            </apex:commandButton>
            <apex:variable var="rowNumber" value="{!rowNumber+1}"/>
          </apex:column>
        </apex:pageBlockTable>
      <!-- </apex:pageblockSection> -->
      <apex:commandButton action="{!addRow}" value="Add Row" reRender="pb"/>      

      <apex:outputText rendered="{!isRerender}">
        <script type="text/javascript">
            var table = document.getElementById('{!$Component.pb.thetable}');
            var lastRow = table.rows[table.rows.length - 1];
            var prevRow = table.rows[table.rows.length - 2];
            var arrSourceInputs = prevRow.getElementsByTagName("input");
            var arrDestInputs = lastRow.getElementsByTagName("input");
            for(var i in arrSourceInputs){
                if(arrSourceInputs[i].type == "text"){
                    arrDestInputs[i].value = arrSourceInputs[i].value; 
                }
            }
        </script> 
      </apex:outputText>           
    </apex:pageBlock>
  </apex:form>

</apex:page>

Apex Class -

public class addRPFchild {
        public RFP__c accounts;
        public Custom_Package__c del;
        public List < Custom_Package__c > addattendeeList {get;set;}
        public List < Custom_Package__c > delattendeeList {get;set;}
        public List < Custom_Package__c > attendeeList {get;set;}
        public Integer totalCount {get;set;}
        public Integer rowIndex {get;set;}
        public List < Custom_Package__c > delAttendees {get;set;}
        public Boolean isRerender{get;set;}
        public addRPFchild (ApexPages.StandardController controller) {

                isRerender = false;
                accounts = (RFP__c ) controller.getRecord();
                attendeeList = [Select id, Name, Market__c, State__c, First_Issue__c,Last_Issue__c,Circulation__c,Space_Unit__c from Custom_Package__c ];
                totalCount = attendeeList.size();

                delattendeeList = new List < Custom_Package__c > ();
                delattendees = new List < Custom_Package__c > ();
        }

        public void addRow() {
                isRerender = true;
                addattendeeList = new List < Custom_Package__c > ();
                attendeeList.add(new Custom_Package__c ());
        }


        public void deleteRow() {

                rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
                System.debug('rowbe deleted ' + rowIndex);
                System.debug('rowm to be deleted ' + attendeeList[rowIndex]);
                del = attendeeList.remove(rowIndex);
                delattendeeList.add(del);

        }
}

Regards

1 Answer 1

-1

Your table is populated from atendeeList, which is initialized in your constructor to be a SOQL query result. That SOQL query finds existing rows, which is why your table shows existing (fully populated) records.

If you want the table to show blank records, rather than initializing atendeeList to a query result, just initialize it to a List of 5 new Custom_Package__c instances.

2
  • Hi.. Still the same issue.... Sep 19, 2015 at 10:00
  • Hi Avrom.. I have looped it 5 times and instatiated inside it.. Thanks for the help Sep 19, 2015 at 11:22

You must log in to answer this question.

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