• Ryan Chen 1
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello,

I'm new to VF & Apex and have been able to get by with most things doing my own research. I'm currently doing a project where I automate an order confirmation page using fields on the order object. 

I know this may be somewhat of a simple problem, but the only roadblock I've come into, is being able to sort the items in my VF table by the unit price. I know of using controller extension SELECT... FROM... ORDER BY... but it doesn't seem to be working. Below is my extension & snippet of the VF table. Could someone please help me out or point me in the right direction for a solution? Thank you so much!

Controller Extension:
public class OrderProductExtension{ 
     public List<OrderItem> getproducts(){
               return products;
     }    
    public OrderProductExtension(ApexPages.StandardController stdController){}
     List<OrderItem> products = 
        [SELECT Quantity, PricebookEntry.Product2.Name, UnitPrice, TotalPrice FROM OrderItem 
         ORDER BY UnitPrice DESC];
}

VF Page Table: 
<apex:pageBlock title="Line Items" >
        <apex:pageBlockTable value="{!Order.OrderItems}" var="oi" >
            <apex:column value="{!oi.Quantity}"/>
            <apex:column value="{!oi.PricebookEntry.Product2.Name}"/>
            <apex:column value="{!oi.UnitPrice}"/>
            <apex:column value="{!oi.TotalPrice}"/>
        </apex:pageBlockTable>
       </apex:pageBlock>
Hello,

I'm new to VF & Apex and have been able to get by with most things doing my own research. I'm currently doing a project where I automate an order confirmation page using fields on the order object. 

I know this may be somewhat of a simple problem, but the only roadblock I've come into, is being able to sort the items in my VF table by the unit price. I know of using controller extension SELECT... FROM... ORDER BY... but it doesn't seem to be working. Below is my extension & snippet of the VF table. Could someone please help me out or point me in the right direction for a solution? Thank you so much!

Controller Extension:
public class OrderProductExtension{ 
     public List<OrderItem> getproducts(){
               return products;
     }    
    public OrderProductExtension(ApexPages.StandardController stdController){}
     List<OrderItem> products = 
        [SELECT Quantity, PricebookEntry.Product2.Name, UnitPrice, TotalPrice FROM OrderItem 
         ORDER BY UnitPrice DESC];
}

VF Page Table: 
<apex:pageBlock title="Line Items" >
        <apex:pageBlockTable value="{!Order.OrderItems}" var="oi" >
            <apex:column value="{!oi.Quantity}"/>
            <apex:column value="{!oi.PricebookEntry.Product2.Name}"/>
            <apex:column value="{!oi.UnitPrice}"/>
            <apex:column value="{!oi.TotalPrice}"/>
        </apex:pageBlockTable>
       </apex:pageBlock>