Ask Search:
Sandy UssiaSandy Ussia 

Sorting related objects in Visualforce PageBlockTable

Hi,
I'm relatively new to Salesforce... not a developer, but I have a background in power user type stuff in SharePoint/Microsoft stack. So not entirely clueless, but also struggling a bit to understand the Salesforce lingo and structure :-)
I've been creating a custom SF app which generally works quite well. But I've run into a problem on a Visualforce page I created, which I just can't seem to get past, after days of searching the forums and documentation, and trying different things - I hope someone can help...
The standard controller I'm using for my "WorkOrder" page is a custom object called WorkOrder, and it has a related object called Piece (i.e. each WorkOrder has multiple Pieces). I'm displaying all of the Pieces for a given Work Order, based on the id being passed in the URL from a button on the Work Order page. I want the Pieces to be displayed in order by Shop Ticket #, but they're in some random order I can't make out. Here's what I've done so far:
- I see some references in the forums to using a custom controller to sort items, but that's not an option for me because I'm on Professional Edition.
- I learned from my research that items within a PageBlockTable are sorted by default in the order of the "current view", and if I create a list view of Pieces where the first column is Shop Tkt #, then if I'm using the Piece controller, this works great. But I need to use the Work Order controller, because I'm displaying all the pieces related to a single Work Order.
- I can see how a SOQL query would be easy (ORDER BY), but I can't find a way to use SOQL outside of a custom controller... Is my understanding correct on this? i.e. is it possible to use SOQL inline somehow within a VF page (not in separate Apex code which I can't do because of my SF edition)? Or can something be passed in the URL of the VF page?
- I also tried implementing a javaScript solution I found called TableSorter, but I couldn't get it to work even with a simple sample table on a VF page in Edge/IE/Chrome, so I wonder if the code is too old or something. Also, it was a bit of overkill, as I don't need to have dynamically sortable columns, I only want to sort the Shop Ticket column before rendering the data.
It seems to me this should be an easy thing to do - like there should be a Sort attribute in the Column or something. As far as I can tell from my research, there's not a solution, but I hope I'm missing something...?
Thanks for any help! 
- Sandy
Best Answer chosen by Sandy Ussia
Nitish SinghalNitish Singhal
Hi Sandy, there is no out of the box solution from Salesforce like putting some attribute in pageblocktable and get the data sorted by column. 

You may need to implement some javascript only, which can help you out.

And yes, if you need more help I would suggest that you will have a better chance of getting relevant answers if you post it on one of the following forums [lots of talented developers out there who must have worked on similar problems before.

StackExchange [http://salesforce.stackexchange.com (http://salesforce.stackexchange.com)]
Official Developer Forum [https://developer.salesforce.com/forums]

For any configuration changes and point and click design solutions, feel free to post in this community and we will be glad to help you out. 

Regards

All Answers

Jeff MayJeff May
This Answers Community is focused on configuration and design questions. Programmatic questions are best submitted to the developer forums at https://developer.salesforce.com where the forums and participants are geared toward programming troubleshooting and support. 
Nitish SinghalNitish Singhal
Hi Sandy, there is no out of the box solution from Salesforce like putting some attribute in pageblocktable and get the data sorted by column. 

You may need to implement some javascript only, which can help you out.

And yes, if you need more help I would suggest that you will have a better chance of getting relevant answers if you post it on one of the following forums [lots of talented developers out there who must have worked on similar problems before.

StackExchange [http://salesforce.stackexchange.com (http://salesforce.stackexchange.com)]
Official Developer Forum [https://developer.salesforce.com/forums]

For any configuration changes and point and click design solutions, feel free to post in this community and we will be glad to help you out. 

Regards
This was selected as the best answer
Sandy UssiaSandy Ussia
Thanks for the feedback, Jeff and Nitish... Sorry about that - I'll head on over to the Developer forum with my question :-)