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
Zach AckermanZach Ackerman 

Visualforce new window and column sorting

I have the following apex and visualforce. 

I have added a commandbutton at the top of the visualforce page, but i want the click to open in a new window. Right now it is opening in the VF window. 

I also want to have the ability to let the user sort the columns by clicking on the column header. 

VisualForce
<apex:page controller="Pagination_min">
    <apex:form >
            <apex:commandButton value="New Opportunity" action="https://cs15.salesforce.com/006/e?retURL=%2F006%2Fo&RecordType=01240000000Uexl&ent=Opportunity"/>
       <apex:pageBlock id="pb">
       
            <apex:pageBlockTable value="{!opps}" var="o">
                <apex:column headerValue="Opportunity Name">  
                      <apex:outputlink value="/{!o.id}" target="__blank">{!o.Name}</apex:outputlink>  
                </apex:column>                  
                <apex:column value="{!o.StageName}"/>
                <apex:column value="{!o.FED__c}"/>
                <apex:column headerValue="Broker">
                <apex:outputlink value="/{!o.Broker__c}" target="__blank">{!o.Broker_Name__c}</apex:outputlink>  
                 </apex:column>    
                <apex:column value="{!o.Core_Product__c}"/>
                <apex:column value="{!o.LeadSource}"/>
                <apex:column value="{!o.Number_Quoted__c}"/>
                <apex:column value="{!o.CreatedDate}"/>
                
            </apex:pageBlockTable>
            <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                </apex:outputPanel>
            </apex:panelGrid>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Apex
 
public with sharing class Pagination_min {

    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 500;
                string OwnersId =  userinfo.getUserId() ;
                string Rectypeid =   '01240000000Uexl';
                string Rectypeid2 = '01240000000cnJS';
                string queryString = 'Select Name, StageName,FED__c,Broker__c,Broker_Name__c,Core_Product__c,LeadSource,Number_Quoted__c,CreatedDate FROM Opportunity Where OwnerId = :OwnersId AND IsClosed = False AND (RecordTypeId = :Rectypeid OR RecordTypeId= :RecTypeId2) order by FED__c';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
     
    Public List<Opportunity> getOpps(){
        List<Opportunity> oppList = new List<Opportunity>();
        for(Opportunity o : (List<Opportunity>)setCon.getRecords())
            oppList.add(o);
        return oppList;
    }
     
    public pageReference refresh() {
        setCon = null;
        getOpps();
        setCon.setPageNumber(1);
        return null; 
    }
}



 
sachin sabusachin sabu
Hi Zach,

Try This
<apex:commandButton value="New Opportunity" onClick="window.open('https://cs15.salesforce.com/006/e?retURL=%2F006%2Fo&RecordType=01240000000Uexl&ent=Opportunity');"/>

 
Zach AckermanZach Ackerman
That worked perfect. Any ideas on how to make the sorting by column headers work for users.