+ Start a Discussion
foodrunnerfoodrunner 

Ordering a DataList - How to write the class

I have the following class to order the quotelineitem related list(datatable).

 

public class orderedLineItems { 
       public Id quoteID {get; set;}
               List<QuoteLineItem> lineItems;
                public List<QuoteLineItem> getlineItems(){
            if(lineItems == null){
                /*Using dyanamic apex and SOQL you could set this up to query all*/
                lineItems = [select Id, PricebookEntry.Name, Quantity, UnitPrice, TotalPrice from QuoteLineItem where QuoteID =:QuoteID];
                lineItems = sortLines(lineItems);
            }
            return lineItems;
        }
        
        private static List<QuoteLineItem> sortLines(List<QuoteLineItem> olis) {
            List<QuoteLineItem> resultList = new List<QuoteLineItem>();
        
            /* Create a map of amount to Opportunity collection */
            Map<String, List<QuoteLineItem>> oliMap = new Map<String, List<QuoteLineItem>>();
            
            for(QuoteLineItem oli : olis) {
                if(oliMap.get(oli.PricebookEntry.Name) == null){ 
                    oliMap.put(oli.PricebookEntry.Name, new List<QuoteLineItem >()); 
                }
                oliMap.get(oli.PricebookEntry.Name).add(oli);
            }
            
            List<String> keys = new List<String>(oliMap.keySet());
            
            /* Leverage the standard, primitive collection sort method */
            keys.sort();
            
            for(String key:keys){ 
                resultList.addAll(oliMap.get(key)); 
            }
            
            return resultList;
        }
}

 

 

Here is my visualforce page:

 

<apex:page standardController="Quote" standardstylesheets="false" renderAs="pdf" showHeader="false">
<head>
<style>
body { font-family: Arial Unicode MS; font-size: 10 px; } 

h3 {
    display:block; width:637px; padding:0; background:#ADD8E6;
    font-size:12px; line-height:23px; text-align:left; font-weight:normal;
}
h4 {
    display:block; width:637px; padding:0; 
    font-size:10px; line-height:12px; text-align:left; font-weight:normal;
}
h5 {
    display:block; width:637px; padding:0; 
    font-size:8px; line-height:12px; text-align:right; font-weight:normal;
}

.header
{
 width: 367x;
 height: 5px;
 background-color: gray;
 color: White;
 font-size:8pt;
 text-align: left;
 padding-left: 5px;
}
.header1
{
 width: 15px;
 height: 5px;
 background-color: gray;
 color: White;
 font-size:8pt;
 text-align: right;
 padding-left: 10px;
}
.header2
{
 width: 65px;
 background-color: gray;
 height: 5px;
 color: White;
 font-size:8pt;
 text-align: right;
 padding: 5px;
}

.tabletop {
    display:block; width:630px; height:5px; 
    background:transparent url(images/top.gif) no-repeat scroll 0 0;
    margin:0 0 0 4px;
}
.tablebk {
    width:615px;
    background:transparent url(images/middle.gif) repeat-y scroll 0 0;
    margin:0 0 0 4px; padding:0 0 0 15px;
}
.tablebottom {
    display:block; width:630px; height:16px; 
    background:transparent url(images/bottom.gif) no-repeat scroll 0 0;
    margin:0 0 0 4px;
}

table {table-layout:fixed; border-collapse:collapse; border-spacing:0; }

th {
    color:#fff; 
    font-size:14px; line-height:10px;
    padding:5px 6px 8px;
    vertical-align:top;
}
td {
    
    font-size:10px; line-height:10px;
    padding:3px;
    vertical-align:top;
}
th.col1,
td.col1 {text-align:left;}
.odd td {background-color:#f2f7fa;}

td input {
    width:85px; height:22px;
    font-size:14px; line-height:16px; font-weight:bold; text-align:left;
    padding-top:3px;
    border:null;
}

tr:hover td {background-color:#599bbd;} /* hover state does not work in ie6 */

/* table1 */
.table1 th.col1 {width:176px; }
.table1 th.col2 {width:181px;}
.table1 th.col3 {width:173px;}
.table1 td {padding-bottom:5px;}
.table1 td.col3 {padding-top:6px; padding-left:19px;}

/* table2 */
.table2 th.col1 {width:176px;}
.table2 th.col2 {width:181px;}
.table2 th.col3 {width:173px;}

/* table3 */
.table3 th.col1 {width:128px;}
.table3 th.col2 {width:153px;}
.table3 th.col3 {width:130px;}
.table3 th.col4 {width:95px;}
.table3 td {padding-bottom:5px;}
.table3 td.col4 {padding-top:6px; padding-left:19px;}
/* END Table CSS */


</style>
</head>

    <apex:form id="theForm">  
       <apex:pageBlock tabStyle="account">
            <apex:pageMessages />
         <apex:image url="/resource/1272645408000/Key_Logo" width="20%" height="20%"/>
           <Table class="table">
           <apex:pageBlockSection title="Essential Information" columns="2"  showHeader="false">
                <apex:outputField value="{!quote.Opportunity.AccountId}" />
                <apex:outputField value="{!quote.quotenumber}" />
                <apex:outputField value="{!quote.BillingAddress__c}" />

                <apex:outputField value="{!quote.Created_Date__c}" />
                <span style="margin-left:-176px; margin-top:-500px; z-index:-1;">
                <apex:outputLabel value="">
                <apex:outputField value="{!quote.BillingAddress2__c}"/>
                </apex:outputLabel>
                                </span>
                <span style="float:left; margin-left:0px; margin-top:-16px;">
                <apex:outputField value="{!quote.ExpirationDate}"/>
                                </span>
                <span style="float:left; margin-left:-176px; margin-top:-6px; z-index:-8;">
                <apex:outputLabel value="">
                <apex:outputfield value="{!quote.BillingCountry}"/>
                </apex:outputLabel>
                </span>                
             </apex:pageBlockSection>

            <apex:pageBlockSection title="Contact Info" showHeader="true" >
                <apex:outputField value="{!quote.contactid}"/>
                <apex:outputField value="{!quote.Phone}"/>
                <apex:outputField value="{!quote.email}"/>
                <apex:outputField value="{!quote.fax}"/>
             </apex:pageBlockSection>

            </Table>
       </apex:pageBlock>
       
       </apex:form>

    <apex:pageBlock >
    <apex:pageBlockSection columns="2">
      <apex:dataTable value="{!Quote.QuoteLineItems}" rowClasses="even,odd," var="line" width="630">
        <apex:column style="text-align:right;" headerClass="header1" headerValue="Item">
        <apex:facet name="header1">Item</apex:facet>
        <apex:outputText value="{!line.Quote_Item_Number__c}" />
        </apex:column>
        <apex:column style="text-align:left;
            border-left-style:solid; border-left-color:black;
            border-left-width:.25px;"  headerClass="header" headerValue="Product">
        <apex:facet name="header">Product</apex:facet>
        <apex:outputText value="{!line.PriceBookentry.name}" />
        </apex:column>        
        <apex:column style="text-align:right;
            border-left-style:solid; border-left-color:black;
            border-left-width:.25px;" headerClass="header2" headerValue="Quantity">
        <apex:facet name="header">Quantity</apex:facet>
        <apex:outputText value="{!line.Quantity}"/>
        </apex:column>
    <apex:column style="text-align:right;
            border-left-style:solid; border-left-color:black;
            border-left-width:.25px;" headerClass="header2" headerValue="Price Each">
        <apex:facet name="header">Price Each</apex:facet>
        <apex:outputText value="{!line.ListPrice}"/>
        </apex:column>
    <apex:column style="text-align:right;
            border-left-style:solid; border-left-color:black;
            border-left-width:.25px;" headerClass="header2" headerValue="Price Each">
        <apex:facet name="header">SubTotal</apex:facet>
        <apex:outputText value="{!line.Subtotal}"/>
        </apex:column>        
      </apex:dataTable>
      </apex:pageBlockSection>
   </apex:pageBlock>
  
        <apex:form >      
       <apex:pageBlock >
       <apex:pageBlockSection columns="2">
       <apex:inputhidden />
       <apex:inputhidden />
       <apex:inputhidden />
       <apex:outputField value="{!quote.Grand_Total__c}" style="h5" />
       </apex:pageBlockSection>

       </apex:pageBlock>
       <apex:pageBlock >
       <h4>
       This quotation is provided for budgetary planning purposes only. 
       This is not an official offer of sale, orders cannot be placed against this Budget quotation. 
       Once project details have been fully defined, a final detailed quotation will be submitted.
       </h4>
       </apex:pageBlock> 
      </apex:form>

</apex:page>

 

Does my class order the quotelineitems by? ItemNumber? What am I missing? How do I attach this onto the visualforce page?

 

Thank you,

foodrunnerfoodrunner

Class Update

public class ItemList{
                List<QuoteLineItem> ItemList;

                public PageReference reset() {
                     ItemList = [select id, Quote_Item_Number__c
                                from QuoteLineItem order by Quote_Item_Number__c ASC];
      
                     return null;
                }  
             
                public List<QuoteLineItem> getQuoteLineItem() {
                     if(ItemList == null) reset(); 
                     return ItemList;
                }
 
                public void setQuoteLineItem(List<QuoteLineItem> qli) {
                      ItemList = qli;
                }
 
                public PageReference save() {
                      upsert Itemlist;
                      return null;
                }
 
                public PageReference add() {
                               ItemList.add(New QuoteLineItem());
                                return null;
                }
 
 
 
}