function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sanjeev342sanjeev342 

How do I dynamically update a dataTable?

Part of my page is a client table that also allows me to insert values into it.

 

How do I insert values and have the table dynamically updated?

 

Code:

    public List<Client__c> clientList {get; set;}
    public Client__c client {get; set;}

 

public void updateClientList(){
        if(clientList == null)
        {
            clientList = new List<Client__c>();
        }
        
        clientList = [SELECT Name, Professional_PracticeID__c, Client_Name__c, StartDate__c, EndDate__c, Pro_Bono__c,  
                      Description__c FROM Client__c WHERE Professional_PracticeID__c=:ProfPracticeID];
        if(client != null){
            clientList.add(client);
        }
        
    }

 

 

      <apex:pageBlock >
            
            <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Add Client" action="{!updateClientList}" reRender="clientDataPanel" />
        </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1" >
            <apex:pageBlockSectionItem >
            <apex:outputLabel value="Client Name" />
            <apex:inputField value="{!client.Client_Name__c}" styleClass="requiredValidation"/>
        </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
            <apex:outputLabel value="Description" />
            <apex:inputField value="{!client.Description__c}" styleClass="requiredValidation"/>
        </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
            <apex:outputLabel value="Start Date" />
            <apex:inputField id="ClientStartDate" value="{!client.StartDate__c}" styleClass="requiredValidation dateField ValidMMYYYY"/>
        </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >  
            <apex:outputLabel value="End Date" />
            <apex:inputField id="ClientEndDate" value="{!client.EndDate__c}" styleClass="requiredValidation dateField ValidMMYYYY"/>
        </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
            <apex:outputLabel value="Pro-Bono" />
            <apex:inputField value="{!client.Pro_Bono__c}" styleClass="requiredValidation"/>
        </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        </apex:pageBlock>
            
            <apex:outputPanel id="clientDataPanel">
                
                <apex:dataTable id="clientDataTable" value="{!clientList}" var="clientRecord" width="100%" rendered="{!IF(clientList != null, true, false)}">
                    <apex:column headerValue="Client Name" width="30%">
                        <apex:outputText value="{!clientRecord.Client_Name__c}"/>
                    </apex:column>
                    <apex:column headerValue="Description of Fund Raising Activities" width="30%">
                        <apex:outputField value="{!clientRecord.Description__c}"/>
                    </apex:column>
                    <apex:column headerValue="Start Date" width="20%">
                        <apex:outputText value="{!clientRecord.StartDate__c}"/>
                    </apex:column>
                    <apex:column headerValue="End Date" width="20%" >
                        <apex:outputText value="{!clientRecord.EndDate__c}"/>
                    </apex:column>
                    <apex:column headerValue="Pro-Bono" width="10%">
                        <apex:outputText value="{!IF(clientRecord.Pro_Bono__c, 'Yes', 'No')}"/>
                    </apex:column>
                </apex:dataTable>
            </apex:outputPanel>

 

This is what I have, and have no clue why it doesn't work. The button doesn't do anything when clicked.

 

Thanks,

Sanjeev

ForcepowerForcepower

Sanjeev,

 

I don't see where you're doing your Insert. If you really wanted the newly entered "client" to get into the database, I think you'd want to do that rather than simply adding it to the end of the list clientList. Other than that issue, the rerender may have an issue with scoping possibly. I would try moving it outside the pageblock and before the output panel for clientDataPanel and see if it works any better.

 

Ram

sanjeev342sanjeev342

Ram,

 

    I'm trying to temorarily save all the values they enter in so that when they finally click a "Save and Review" button on the page (and after other fields have been filled out), all the items in the clientList will be commited to the database.

 

Thanks,

Sanjeev

ForcepowerForcepower

ok - got it. Did you try moving the Command button (or link) and did it make any difference to the rerender? If you're getting stuck on it, one quick fix is to rerender the whole page by returning a page reference of null from your action method. You would need to change the signature of the method though obviously.