You need to sign in to do that
Don't have an account?
Jennifer Jobson 9
How to order a related list on a visualforce template
I have a table in a visualforce template that I need ordered by date. Here is the code currently:
<table border="0" >
<tr >
<th>Product</th> <th>Price</th> <th>Quantity</th> <th>UOM</th> <th>Number of Pallets</th> <th>Total Weight</th> <th>Pickup Date</th> <th>Comments</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Product_Entries__r}">
<tr><td>{!cx.Product__r.Name}</td>
<td> {!cx.Price__c}</td>
<td> {!cx.Quantity__c}</td>
<td> {!cx.UoM__c}</td>
<td> {!cx.Number_of_Pallets__c}{!cx.Florisil_Number_of_Pallets__c}</td>
<td> {!cx.Total_Weight_including_pallets__c}{!cx.Florisil_Line_Item_Total_Weight__c}</td>
<td> <apex:outputText value="{0, date, MMMM d',' yyyy}">
<apex:param value="{!cx.Pickup_Date__c}" />
</apex:outputText></td>
<td> {!cx.Comments__c}</td>
</tr>
</apex:repeat>
</table>
And here is how it looks:
How do I get the list to sort by pickup date? Thanks for any help!
<table border="0" >
<tr >
<th>Product</th> <th>Price</th> <th>Quantity</th> <th>UOM</th> <th>Number of Pallets</th> <th>Total Weight</th> <th>Pickup Date</th> <th>Comments</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Product_Entries__r}">
<tr><td>{!cx.Product__r.Name}</td>
<td> {!cx.Price__c}</td>
<td> {!cx.Quantity__c}</td>
<td> {!cx.UoM__c}</td>
<td> {!cx.Number_of_Pallets__c}{!cx.Florisil_Number_of_Pallets__c}</td>
<td> {!cx.Total_Weight_including_pallets__c}{!cx.Florisil_Line_Item_Total_Weight__c}</td>
<td> <apex:outputText value="{0, date, MMMM d',' yyyy}">
<apex:param value="{!cx.Pickup_Date__c}" />
</apex:outputText></td>
<td> {!cx.Comments__c}</td>
</tr>
</apex:repeat>
</table>
And here is how it looks:
How do I get the list to sort by pickup date? Thanks for any help!
Hi Jennifer Jobson 9,
You can use order by Pickup_Date__c desc OR order by Pickup_Date__c asc from where you are quering (add in the end of the query).
Eg:- Select id,name, createddate from Account order by createddate desc
Please mark it is best answer if this helps you.
Thanks,
Arun
To order the table by date, you can use the order by clause in your SOQL query that retrieves the Product_Entries__r records.
Assuming that the Product_Entries__r relationship field is a child relationship to the parent object, you can modify your query to include an ORDER BY clause that sorts by the Pickup_Date__c field:
This should display the table rows in ascending order based on the Pickup_Date__c field value.
If you find my answer helpful, please mark it as the best answer. Thanks!
Thanks,
Jennifer