function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jls_74_txjls_74_tx 

OMG...Why Is Sorting A Related List So Complicated?

I have created a very simple VF page that renders as a PDF for my apartment clients that displays all of floor plans from a related list. Here is the page:  http://aim.force.com/apex/Competitive_Property_Report?ID=a09A0000001OXor

 

(It's not formatted yet, I stopped to try to figure out this sort issue - it's pretty ugly right now)

 

I want to sort the table by column 3 - square feet - smallest to largest. - that's it.

 

Thank you in advance for your help.

bvramkumarbvramkumar

It seems you are using apex:relatedList to show the "floor plans". Correct? Otherwise, you would not really worry because SOQL has the order by clause to make it sorted.

 

apex:relatedList does not have an attibute to set the sort column. But the pagelayouts do...

 

Go to the EditLayout for your particular master object of "floor plans". and edit the "floor plans" related list...  and select the "sqare feet" field in the "Sort By" drop down. select "ascending" below.

 

Now, when you use apex:relatedList... your pdf report would show the floor plans sorted by "sqare feet" column...

 

I tried it before posting here... and added it to my site...

 

her it is: http://bvramkumar-developer-edition.ap1.force.com/RamTest__testRelatedList?Id=00190000006B5j3

 

Hope this helps.....

 

Happy Coding...

 

 

jls_74_txjls_74_tx

Yes, you are correct I am using a apex:relatedList.  I already have square feet as the sort by selection in the master object "Market Information".  This isn't one of my page layouts though.  I have two page layouts:  1. Admin (for me and my staff) and 2. aimMLS (for my customer portal users).  Both show square feet as the sort order on the related lists.

 

The "Printable View" from the Customer Portal was several pages long so I created this custom VF Page using HTML and the PageBlockTable with the related list and rendered as a PDF to serve as the new "Printable View" and I'm going to create a custom button on the aimMLS page layout so when an apartment manager clicks it, this page opens in a new window:  http://aim.force.com/apex/Competitive_Property_Report?ID=a09A0000001OXor

and they can print.

 

I'm a beginner at VF but is using the apex:dataTable how I utilize SOQL?

 

Thank you so much for your response.

 

 

 

bvramkumarbvramkumar

So... setting the sqare feet column in sort by column dint work for you? weird because... I just tried a sample before posting here.... to make sure it works... really making doubt consistency of standard VF components.... I wish I am wrong... 

 

You can use apex:dataTable with an SOQL to get the desired data with sort by any column.... You need to use Order by sqare_feet__c in your SOQL.... i.e. your query should look like Select <field list> from <custom object> Where <filter criteria> Order by sqare_feet__c;

 

you can also use components like apex:pageBlockTable and apex:repeat to get the data in tabular format...

 

here is an example of data table...

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_dataTable.htm

 

Happy Coding...

 

 

 

 

jls_74_txjls_74_tx

 

I got the related list sort order to work for me but it doesn't have the ability to style the result so the formatting wasn't good enough.

 

I used the pageblockTable and got it to work with the style but I'm back to the same problem with the sorting.

 

So I took your advice and built my first controller in my sandbox for a data table but I have a few questions if you still have time to help me.

 

  1. How do I select fields from two custom objects?
  • The majority of the data is from Property__c with a master-detail relationship from Availability__c (child relationship Floor_Plan1__r) which holds the list of floor plans at each apartment.
  • Here is my controller, and it works fine, sorts the list by square feet as you recommended.

 

public class dataTableCon {

 

List<Availability__c> availability;

 

public List<Availability__c> getMyfloorplans() {


return [SELECT Floor_Plan_Nickname__c, Unit_Mix__c, FF_Unit_Type__c, Square_Feet__c, Deposit__c, Cars__c, W_D__c, Gross_Rent__c, PSF__c, Monthly_Rent_Special__c, Eff_PSF__c, Concession_2__c, Vacant__c, Next_Date_Available__c FROM Availability__c ORDER BY FF_Unit_Type__c, Square_Feet__c];
return availability;
}
}

 

 

2. I developed this in my sandbox...how do I get it into production?  I tried to run a test but the controller name doesn't pop up on the list of options.  I clicked Run All Tests but I still can't figure out how to move it to production.

 

My developer's wife is having a baby so I'm trying to figure this out without bothering him.  Thank you in advance for your help!!