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
PreussenBlauPreussenBlau 

Contact DataTable Sorting

The datatable of contacts is not displaying the new sort order after the group of contacts is changed due to the user changing the Account.

 

A user creates a new material orders record based on our custom object.  The VF page displays the Account name and the associated contacts tied to the account from where the user clicked the new material orders record button.  The contacts tied to the account are displayed in a datatable.  The user can sort the contacts by one of several columns related to contact data.  In addition, the contacts are contained within a wrapper class for the purpose of adding a select checkbox next to each contact.  Everything works fine, both the selection and the sorting of contacts.

 

But the user also has the option of selecting a different account.  If the user selects a new Account from the Account lookup field on the custom object, I do a PageReference which calls a few methods to pull the contacts associated with the new account.  The Contact table displays the new group of contacts without a problem.  However, when the user tries sorting the contacts for the new account, the contact datatable does not display the new sort order.  The View State indicates that the new group of contacts have not been sorted.  But my debug variable in the System Log shows me that in fact the contacts were sorted on the back end.  And in fact the response time from when the user clicks the column to sort and when the display changes would suggest that sorting is occuring.  Selecting the contact checkbox also does not appear to work in the View State (boolean remains false) though the display on the VF page shows the contact selected.

 

The sort functionality is an algorithym which is rather lengthy so I'd rather avoid adding it here.  I've tried using an actionFunction and actionSupport but I cannot get the VF page to display the new sort order of the contacts after I've changed the Account and refreshed the datatable of contacts.  The database displays the new group of contacts but clicking on columns does not display a new sort order as it did with the initial account.  Again, I'm certain from what I've seen in the System Log that the contacts are sorting properly.   The new sort order just doesn't render or show on the VF page.  Any help would be greatly appreciated. 

 

----------------------

<!-- ACCOUNT LOOKUP PANEL--> 
         <apex:pageBlockSectionItem >
            <apex:outputPanel id="AccountLookUp" title="AccountLookUp" rendered="{!searchOptions=='ByAccount'}">
               <div style="font-weight:bold;color:black;position:relative;left:350px;margin-top:0px;margin-bottom:3px"> Account &nbsp;         
                  <apex:inputField id="MO_Account"  value="{!Material_Order__c.Account__c}" style="font-weight:normal;width:400px;color:black;margin-                     top:15px;margin-bottom:3px">
                   </apex:inputField>    
                     <br/>
                  <apex:commandButton value="Lookup Contacts for this Account" action="{!refreshContacts}" reRender="contactPanel" style="position:relative;left:50px;margin-top:1px;margin-bottom:1px" status="status">
                  </apex:commandButton>
               </div>
            </apex:outputPanel>
         </apex:pageBlockSectionItem>

 

---------------------

 

 

<apex:outputPanel layout="block" id="contactPanel" style="position:relative;width:50%;left:200px">

   <apex:actionStatus id="contactStatus">
      <apex:facet name="stop">

         <apex:pageBlock title="Contacts for {!AccountName}"  rendered="{!AND(searchOptions=='ByAccount',ShowContacts==true)}">
<!--CONTACT DATA TABLE -->                       
       <apex:dataTable value="{!Contacts}" id="contactDataTable" var="listContacts" rows="{!ContactRowInc}" first="{!ContactRowMin}" width="100%">
<!--   CONTACT SELECT CHECKBOX COLUMN -->
             <apex:column >
                <apex:facet name="header"/>          
                    <apex:inputCheckbox value="{!listContacts.selected}" onclick="deSelectOthers(this)"/>
                    <apex:actionSupport event="onclick" reRender="refreshSelected"/>
             </apex:column>          

 

<!--   CONTACT NAME COLUMN -->
             <apex:column >
                <apex:facet name="header">
                   <apex:commandLink action="{!sortContactsByName}" onclick="deSelectAll(this)" reRender="contactPanel" status="nameCSortStatus">
                      <apex:actionStatus id="nameCSortStatus" startText="(Sorting...)">
                         <apex:facet name="stop">
                            Contact Name {!IF(ConSortBy == 'Name', IF(ConSortAsc,'▼','▲'),'')}
                         </apex:facet>
                      </apex:actionStatus>
                   </apex:commandLink>
                </apex:facet>

<!--   URLFOR allows us to display a single contact in a new Window.  -->
                   <apex:outputLink value="{!URLFOR($Action.Contact.View, listContacts.contact.Id)}" target="_blank">
                          {!listContacts.contact.Name}
                    </apex:outputLink>
             </apex:column>

 

<!--   CONTACT TITLE COLUMN -->
             <apex:column >
                <apex:facet name="header">
                   <apex:commandLink action="{!sortContactsByTitle}" onclick="deSelectAll(this)" reRender="contactPanel" status="titleCSortStatus">
                      <apex:actionStatus id="titleCSortStatus" startText="(Sorting...)">
                         <apex:facet name="stop">
                            Title {!IF(ConSortBy == 'Title', IF(ConSortAsc,'▼','▲'),'')}
                         </apex:facet>
                      </apex:actionStatus>
                   </apex:commandLink>
                 </apex:facet>
                 {!listContacts.contact.Title}
             </apex:column>

 

<!--   CONTACT FUNCTIONAL ROLE COLUMN -->            
             <apex:column >
                <apex:facet name="header">
                   <apex:commandLink action="{!sortContactsByRole}" onclick="deSelectAll(this)" reRender="contactPanel" status="roleCSortStatus">
                      <apex:actionStatus id="roleCSortStatus" startText="(Sorting...)">
                         <apex:facet name="stop">
                            Functional Role {!IF(ConSortBy == 'Role', IF(ConSortAsc,'▼','▲'),'')}
                         </apex:facet>
                      </apex:actionStatus>
                   </apex:commandLink>
                </apex:facet>
                {!listContacts.contact.FUNCL_ROLE_DESC__c}
             </apex:column>

 

<!--   CONTACT EMAIL ADDRESS COLUMN -->            
             <apex:column >
                <apex:facet name="header">
                   <apex:commandLink action="{!sortContactsByEmail}" onclick="deSelectAll(this)" reRender="contactPanel" status="emailCSortStatus">
                      <apex:actionStatus id="emailCSortStatus" startText="(Sorting...)">
                         <apex:facet name="stop">
                            Email {!IF(ConSortBy == 'Email', IF(ConSortAsc,'▼','▲'),'')}
                         </apex:facet>
                      </apex:actionStatus>
                   </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!listContacts.contact.Email}" />
             </apex:column>
            
<!--   CONTACT PHONE COLUMN -->
             <apex:column >
                <apex:facet name="header">
                   <apex:commandLink action="{!sortContactsByPhone}" onclick="deSelectAll(this)" reRender="contactPanel" status="phoneCSortStatus">
                      <apex:actionStatus id="phoneCSortStatus" startText="(Sorting...)">
                         <apex:facet name="stop">
                            Phone {!IF(ConSortBy == 'Phone', IF(ConSortAsc,'▼','▲'),'')}
                         </apex:facet>
                      </apex:actionStatus>
                   </apex:commandLink>
                </apex:facet>
                {!listContacts.contact.Phone}
             </apex:column>

             <apex:outputText id="refreshSelected" value="{!selectedContact.name}" />      
     
       </apex:dataTable>

 

---------------------------------