You need to sign in to do that
Don't have an account?

Sort table on PDF Visualforce
I have a controller for my custom object that is currently sorting columns in my table. However, it's sorting on every column.
How do I adjust the code to only sort on columns/fields that I specify?
public class ExhibitAController { public Customer_Pricing__c cust {get;set;} public List<Customers_Product_Code__c> customerproducts {get;set;} public ExhibitAController(ApexPages.StandardController stdController){ this.cust = (Customer_Pricing__c)stdController.getRecord(); customerproducts = [select Description_for_Invoice__c,TSDF_Approval_Number__c,Caveats__c,Category__c,Container_Size__c,UM__c,Price__c from Customers_Product_Code__c where Customer_Pricing__c =:cust.Id]; customerproducts.sort(); } }
How do I adjust the code to only sort on columns/fields that I specify?
All Answers
You need a wrapper class and to adapt your Visualforce page using this wrapper class.
Custom Sort Order of sObjects: To implement a custom sort order for sObjects in lists, create a wrapper class for the sObject and implement the Comparable interface. The wrapper class contains the sObject in question and implements the compareTo method, in which you specify the sort logic.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_list_sorting_sobject.htm
and therefore:
public CustomerPricingWrapper custw {get;set;} have to be used in your VFP instead of Customer_Pricing__c cust.
custw.cust.Container_Size__c
Regards
Why don't you use ORDER BY in you SOQL. It will help you in sorting only the fields you want to sort.
Read here for more info : https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_orderby.htm
Regards
: customerproducts.sort();if you use "SELECT ... ORDER BY columns" directly instead.Thank you for your input! I was able to get the controller to work once I removed the previous customerproducts.sort();