2

I have come up against a wall and I am hoping my options are not as bleak as they seem...

I am trying to create a simply list view on a visualforce page. I am not requiring assistance with any coding so I am not going to post any; instead I simply need an answer to this question:

I want to consume a list object in an apex class, which specifically is a list of opportunities that meet a specific set of criteria. I then wish to display these records in a visualforce table of sorts (not fussed which table type is used) and limit the number of rows per page ie set it to 20 and there will be a next and previous button like the enhanced table.

Th wall I have hit is that normal table elements like page block table do not allow the limiting of rows per page, and require heavy javascript/jquery (especially if you wish to implement sorting via letter etc) and the enhanced list view only accepts entire objects and do not work with a list object from an apex class. Is my understanding correct? If so, is there a solution other than jquery tabs?

2

You have two options. You can either use offset in SOQL query and build a custom pagination. You can give offset values up to 2000. Or using stadnardsetcontroller you can build a pagination which allows you to paginate up to 10k records. Please check the link below, https://developer.salesforce.com/page/Paginating_Data_for_Force.com_Applications

You can add sorting in both of these pagination with additional coding.

1

It sounds like you could do that by using the list to construct a StandardSetController and then use the setPageSize, next, and previous methods for your pagination.

0

Sorry to be answering my own question - I actually came up with a solution in the mean time and simply if anyone comes across this here is my solution:

Using the enhancedList element you can customise the filtering. Simply create a list view on the object and then specify the list view ID in the ListId parameter on the enhanced list element. In my example below, I have put my IDs into custom labels for deployment sake.

Visualforce page:

<style>
    .controls{
        display:none;
    }
</style>

<apex:form >
    <apex:selectList value="{!selectedView}" size="1" multiselect="false" styleClass="viewSelect" style="min-width: 200px;padding: 4px 6px;margin: 4px 5px 4px 0px;font-weight: bold;">
        <apex:actionSupport event="onchange" rerender="tableArea" status="searchStatus" />
        <apex:selectOptions value="{!Views}" />
    </apex:selectList>
    <apex:actionStatus id="searchStatus"><apex:facet name="start">Loading...</apex:facet></apex:actionStatus>
</apex:form>

<apex:outputPanel id="tableArea">
    <apex:outputPanel rendered="{!IF(selectedView == 'All', true, false)}">
        <apex:enhancedlist type="Opportunity" height="730" customizable="false" rowsPerPage="25" Listid="{!$Label.TAB_Opportunities}" />
    </apex:outputPanel>

    <apex:outputPanel rendered="{!IF(selectedView == 'My', true, false)}">
        <apex:enhancedlist type="Opportunity" height="730" customizable="false" rowsPerPage="25" Listid="{!$Label.TAB_My_Opportunities}" />
    </apex:outputPanel>

    <apex:outputPanel rendered="{!IF(selectedView == 'Open', true, false)}">
        <apex:enhancedlist type="Opportunity" height="730" customizable="false" rowsPerPage="25" Listid="{!$Label.TAB_Open_Opportunities}" />
    </apex:outputPanel>
</apex:outputPanel>

Apex Class:


public class opportunityTab{
public String selectedView {get;set;}
public opportunityTab(){
selectedView = 'All';
}
public List getViews() {
List options = new List();
options.add(new SelectOption('All','All Opportunities'));
options.add(new SelectOption('My','My Opportunities'));
options.add(new SelectOption('Open','Open Opportunities'));
return options;
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.