I have a visualforce page using an apex:repeat tag like this :
<apex:page applyBodyTag="false" applyHtmlTag="false" sidebar="false" showHeader="false" renderAs="pdf" standardcontroller="Quote" extensions="DevisPDFController" action="{!savePDF}">
<apex:repeat value="{!Quote.QuoteLineItems}" var="item" >
<tr>
<td class="lignesPrix" style="width:60%;max-width:60%; border-left:0px;"><apex:outputText value="{!item.Product2.name}"/></td>
<td class="lignesPrix" style="text-align: right;"><apex:outputText value="{!item.Prix_de_vente_HT_unitaire__c} €"/></td>
<td class="lignesPrix" style="text-align: right;" ><apex:outputText value="{!item.Quantity}"/></td>
<td class="lignesPrix" style="text-align: right;" ><apex:outputText value="{!item.Prix_de_vente_HT_total__c} €"/></td>
<td class="lignesPrix" style="text-align: right;" ><apex:outputText value="{!item.Prix_de_vente_TTC_total__c} €"/></td>
</tr>
</apex:repeat>
</apex:page>
In my apex controller (it's an extension) I have that :
public class DevisPDFController {
public Quote devisItem{get;set;}
public string idVal{get;set;}
public string doSave{get;set;}
public List<QuoteLineItem> lLignesDevis{get;set;}
public DevisPDFController(ApexPages.StandardController stdController){
idVal = stdController.getId();
System.debug('### idVal : ' + idVal);
doSave = ApexPages.currentPage().getParameters().get('doSave');
devisItem = [Select ID, Name, OpportunityId, QuoteNumber, lastmodifieddate From Quote where ID = :idVal];
lLignesDevis = [SELECT Id, Prix_d_achat_HT_unitaire__c, Prix_de_vente_HT_total__c, Prix_de_vente_TTC_total__c,
Quantity, Product2Id, Product2.Name, Product2.ProductCode, Prix_de_vente_HT_unitaire__c, product2.family
FROM QuoteLineItem
WHERE QuoteId = :idVal
ORDER BY Product2.ProductCode ];
}
public pageReference savePDF(){
if(doSave == 'No'){
return null;
}
PageReference pagePdf = new PageReference('/apex/DevisPDF');
pagePdf.getParameters().put('id', idVal);
pagePdf.getParameters().put('doSave', 'No');
Blob pdfPageBlob;
pdfPageBlob = pagePdf.getContentAsPDF();
Attachment a = new Attachment();
a.Body = pdfPageBlob;
a.ParentID = idVal;
a.Name = 'Devis : ' + devisItem.QuoteNumber + '.pdf';
a.Description = devisItem.name;
insert a;
return new PageReference('/' + idVal);
}
}
I tried to use the order by in my query, but it doesn't work; my items are not sorted by the Product2.ProductCode field.
Is there a way to do that ? It's a VF page used in PDF with a standard controller and an extension (with the code above)
Quote.QuoteLineItems
being iterated upon in your VF but I don't see it assigned in your Apex. It doesn't appear you're referencing the same things. Furthermore, I can't think of any reasons why theORDER BY
clause wouldn't be sorting - though it may not be sorting in a way that you desire (e.g. sorting numbers like 1,10,11,2,20). There isn't any way to sort this data once it's on the VF page, so I would focus on sorting either in the SOQL query or by using asort()
method.lLignesDevis