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
Mohan Raj 33Mohan Raj 33 

Can any one known a dynamic query for the datatable of Accounts and Contacts and I want a dynamic query for the make a mouse click to that column it's give an order of "ascending" and the double click it gives "descending"order

Already I have a controller for the task as below:
public class ContactListController {
    public List<Contact> ContactList {
        get {
            If(Contact.Account.Name != Null) {
                If(ContactList == Null) {
                    ContactList = [SELECT Name, Account.Name, Phone, Email, MailingCity, MailingState, MailingPostalCode FROM Contact WHERE Account.Name != Null 
                                      ORDER BY Account.Name ASC]; 
                } 
            }
            return ContactList;
        }
           set;
    } 
}

the page for this controller is:
<apex:page controller="ContactListController"> <apex:form > <apex:pageBlock > List Of Contacts with Accounts: <apex:pageBlockTable value="{!ContactList}" var="contact" cellpadding="0" cellspacing="0" width="50%"> <apex:column value="{!contact.Account.Name}" onclick="ascending" ondblclick="descending"/> <apex:column value="{!contact.Name}"/> <apex:column value="{!contact.Phone}"/> <apex:column value="{!contact.Email}"/> <apex:column value="{!contact.MailingCity}"/> <apex:column value="{!contact.MailingPostalCode}"/> <apex:column value="{!contact.MailingState}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>


But now i want to dynamic query to the  if I click the mouse to the column of each in the table it's give the ascending order and then I click the double click it's give the descending order for the table data.

thank you 
Mohan Raj
praveen sonepraveen sone
Mohan,

This link can give you an idea. Check the comments section which has code example of how to make use of ASC and DESC on any column.

https://developer.salesforce.com/forums/?id=906F00000008z8TIAQ
 
Mohan Raj 33Mohan Raj 33
thank you for redirecting to me.
Mohan Raj 33Mohan Raj 33
I have seen the code but actually I am new in the apex so I am difficult to understand Can any one explain that code please.?