You need to sign in to do that
Don't have an account?
jls_74_tx
Sort PageBlockTable
I'm a total newbie to writing controllers, but I would like to learn.
How do I sort a PageBlockTable? I have read several posts on here and understand I need to use the ORDER BY statement but I'm lost how to implement it in a controller.
Please Help!
Do you want it sorted by default or should it become sorted when the user clicks a column?
Can you post your code? At least wherever you build the list of objects used in your page block table.
You should be using a list which will populate data in your page block table. This list is populated from the query running in your controller. Just add an order by 'field name' clause at the end of the query, and you will be good.
Please mark it as Solved if this helps you, so that others can benefit!
~Sumit
I just realized when I replied SURE from my email, the code didn't come through. Here is it....sorry about that:
<apex:page sidebar="false" showHeader="false" cache="false" standardController="Apartment__c" contentType="application/vnd.ms-excel#availability.xls" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Apartment__c.Units__r}" var="item">
<apex:column value="{!item.ID}" />
<apex:column value="{!item.Unit_Number__c}" />
<apex:column value="{!item.Nickname__c}" />
<apex:column value="{!item.Available__c}" />
<apex:column value="{!item.Bedrooms__c}" />
<apex:column value="{!item.Bathrooms__c}" />
<apex:column value="{!item.Square_Feet__c}" />
<apex:column value="{!item.Layout__c}" />
<apex:column value="{!item.Rent__c}" />
<apex:column value="{!item.Deposit__c}" />
<apex:column value="{!item.Washer_Dryer__c}" />
<apex:column value="{!item.Attached_Garage__c}" />
<apex:column value="{!item.Wheelchair_Accessible__c}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>