You need to sign in to do that
Don't have an account?
ab84
Sorting results in visualforce
I have a visual force page that displays all ideas in a page block table. I want to add a link to the side of the table that reads “Most discussed”. When clicking on it, the ideas displayed will be sorted by the number of comments.
Likewise, I want another link that says “popular” and when clicked it’ll sort by the number of votes.
I’ve had a look at the below:
https://help.salesforce.com/apex/HTViewSolution?id=000171025&language=en_US
This kind of covers what I’m looking to do however I’m not sure how to implement the sort options. My page uses a standard controller with an extension.
Can anyone suggest how I would code the sort options in the apex class and then implement in visual force?
Likewise, I want another link that says “popular” and when clicked it’ll sort by the number of votes.
I’ve had a look at the below:
https://help.salesforce.com/apex/HTViewSolution?id=000171025&language=en_US
This kind of covers what I’m looking to do however I’m not sure how to implement the sort options. My page uses a standard controller with an extension.
Can anyone suggest how I would code the sort options in the apex class and then implement in visual force?
The one easiest solution is that on the click of that link you need to get the result sorted DESC based on the your criteria field.
Say for example for most number of votes I suppose you are incrementing one field value so you can have a query like
Let us consider that the field type for the votes field is Number and the field name is votes__c and Object name is PropertyUnit__c
Please have a look on the below link
http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_orderby.htm
Let me know if you have any issue.
Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
All Answers
The one easiest solution is that on the click of that link you need to get the result sorted DESC based on the your criteria field.
Say for example for most number of votes I suppose you are incrementing one field value so you can have a query like
Let us consider that the field type for the votes field is Number and the field name is votes__c and Object name is PropertyUnit__c
Please have a look on the below link
http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_orderby.htm
Let me know if you have any issue.
Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
https://help.salesforce.com/apex/HTViewSolution?id=000171025&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000171025&language=en_US)
Remember you need to reRender the section with the updated data
In the example you gave, is Select_Sorting_parameter__c a custom field on the object?
If not refer to this link --http://gtr.net/visualforce-attributes-rendered-re-render-and-renderas/
Another thing you need is to sort the result for that paste your SOQL here
What you need to do is to use orderBy filedName DESC
provided your field is integer type
I guess I need to have some kind of if statement so that if a selection is made the different SOQL is called. How would I handle this if it was a hyperlink that showed the options of most discussed or popular rather than a drop down list?
I have achieved that using the below sample code
In Apex Page Controller
Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
The field categories comes through as a multi-select...is there any way for me to make this appear as a single pick list (drop down menu) in visualforce instead?
I used apex:selectOptions and apex:list to surface the items on the VF page and then a pagereference to refresh the page.