You need to sign in to do that
Don't have an account?

How to sort Columns of apex:pageBlockTable in visualforce page
Hi guys thanks for taking interest in my question
Can you please help me in my code I want to sort my apex:pageBlockTable columns after clicking on that particular column
here are my APEX and VF code which is sorting only one column but what I want, when I click on a particular column header that column will sort again I click on same column header it should reverse
//SAJCustomerContactExt
Can you please help me in my code I want to sort my apex:pageBlockTable columns after clicking on that particular column
here are my APEX and VF code which is sorting only one column but what I want, when I click on a particular column header that column will sort again I click on same column header it should reverse
<apex:page standardController="Account" extensions="SAJCustomerContactExt"> <apex:slds /> <style> .fewerMore { display: none;} </style> <apex:pageblock id="CustomList" rendered="{!contacts.size != 0}"> <!----> <apex:pageBlockTable value="{!contacts}" var="c"> <apex:column headerValue="Contact Name"> <apex:outputLink value="/{!c.id}" id="contactLink" target="_parent"> {!c.Name} </apex:outputLink> </apex:column> <apex:column value="{!c.FirstName}"/> <apex:column value="{!c.Department}"/> <apex:column value="{!c.Email}"/> <apex:column value="{!c.LastName}"/> <apex:column value="{!c.Phone}"/> <apex:column value="{!c.Title}"/> </apex:pageBlockTable> </apex:pageblock> </apex:page>
//SAJCustomerContactExt
public class SAJCustomerContactExt { private List<Contact> contacts; private Account acct; public SAJCustomerContactExt(ApexPages.StandardController stdcontroller) { this.acct = (Account)stdcontroller.getRecord(); } public List<Contact> getContacts() { contacts =[SELECT Id, Name,FirstName, Department,Email, LastName,Title, Phone FROM Contact where AccountId =: acct.ID ORDER BY Name LIMIT 900]; System.debug('DATA SUCCSESSFULLY QUERIED....! '+contacts); return contacts; } }
Here is a simple but very powerful trick when you want to sort the columns with very few lines of code by using jquery and datatables.js
https://datatables.net/