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
Vaibhav Shete 1Vaibhav Shete 1 

how to do sorting asc and dec order for created date in custom vf page

how to do sorting asc and dec order for created date in  custom vf page
Khan AnasKhan Anas (Salesforce Developers) 
Hi Vaibhav,

Greetings to you!

Please refer to the below link which might help you further with the above requirement.

http://bobbuzzard.blogspot.com/2014/09/sorting-visualforce-tables-with.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Ajay K DubediAjay K Dubedi
Hi Vaibhav,

Click on this link helpful for you.

http://sfdcsrini.blogspot.com/2014/09/sorting-tables-in-visualforce.html

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Deepali KulshresthaDeepali Kulshrestha
Hi Vaibhav,


Greetings to you!

I have gone through your query please try below code:

vf page
---------------------------------------------
<apex:page controller="Sorting_Controller">
 <apex:form >
  <apex:pageBlock >
   <apex:panelgrid columns="2">
    <apex:selectList value="{!selectedField }" size="1">
     <apex:selectOption itemValue="Name" itemLabel="Account Name"/>
     <apex:selectOption itemValue="AccountNumber" itemLabel="Account Number"/>
    </apex:selectList>
    <apex:commandButton value="Sort Table" action="{!sortMethod}" reRender="pgblcktbl"/>
   </apex:panelgrid>
  </apex:pageBlock>
  <apex:pageBlock id="pgblcktbl">
   <apex:pageblocktable value="{!accList}" var="rec" >
     <apex:column value="{!rec.name}"/>
     <apex:column value="{!rec.accountnumber}"/>
   </apex:pageblocktable>
  </apex:pageBlock>
 </apex:form>
</apex:page>
----------------------------------------------
Controller class
----------------------------------------------
public class Sorting_Controller {
    Public List<account> accList{get;set;}
    Public string selectedField {get;set;}
    Public Sorting_Controller(){
        accList = [select name,accountnumber from account limit 10];
    }
    Public void sortMethod(){
        if(selectedField == 'Name')
            accList = [select name,accountnumber,annualrevenue from account where id IN:accList order by Name limit 100 ];
        else if(selectedField == 'AccountNumber')
            accList = [select name,accountnumber,annualrevenue from account where id IN:accList order by AccountNumber limit 100 ];
    }
}
    
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
 
Vaibhav Shete 1Vaibhav Shete 1
It's not working can u plz check once