0

standardSetControllerを使用したページ付けのあるvisualforceページがあります。このページでは、ステータスによるフィルタリングも追加しました。つまり、新規、作業中、終了などです。現在、各ステータス値に対してcount()を実行して、ページにステータスカウントを表示していますが、ステータスごとにクエリが必要ですが、これは非効率的です。より効率的な方法でステータスカウントを取得したいと思います。

これが私のコントローラーです:

public with sharing class myController {

public ApexPages.StandardSetController setCtrl{get; set;}
public String projId { get; set; }
public String clientName { get; set; }
private List<Ticket__c> TicketList = new List<Ticket__c>();

public myController()
{
    projId = ApexPages.currentPage().getParameters().get('id');
    clientName = [Select Client__r.Name From Project__c Where Id =: projId].Client__r.Name;
    setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId ORDER BY CreatedDate DESC]));
    ticketList = (List<Ticket__c>)setCtrl.getRecords();
    setCtrl.setPageSize(5);
}

public Integer getNewStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'New'];
}

public Integer getWorkingStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Working'];
}

public Integer getResolvedStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Resolved'];
}

public Integer getClosedStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Closed'];
}

public Integer getCancelledStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Cancelled'];
}

public Integer getReopenedStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Reopened'];
}

public Boolean hasNext {
    get {
        return setCtrl.getHasNext();
    }
}

public Boolean hasPrevious {
    get {
        return setCtrl.getHasPrevious();
    }
    set;
}

public Integer pageNumber {
    get {
        return setCtrl.getPageNumber();
    }
    set;
}

public Integer totalPages {
    get {
        totalPages = math.ceil((Double)setCtrl.getResultSize() / setCtrl.getPageSize()).intValue();
        return totalPages;
    }
    set;
}

public void first() {
    setCtrl.first();
}

public void last() {
    setCtrl.last();
}

public void previous() {
    setCtrl.previous();
}

public void next() {
    setCtrl.next();
}


public List<Ticket__c> getTickets()
{
    return (List<Ticket__c>)setCtrl.getRecords();
}

public void filterStatus() {
    string myParam = apexpages.currentpage().getparameters().get('myParam');
    setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId AND Status__c =: myParam ORDER BY CreatedDate DESC]));
    setCtrl.setPageSize(5);
}
}

VFコードは次のとおりです。

                <div class="contact-form">


                    <apex:outputPanel id="contactForm">
                        <apex:form >
                            <ul class="filteredView">
                                <li>
                                    <apex:outputLink value="/tickets?id={!projId}">View All</apex:outputLink>
                                </li>
                                <li>
                                    ({!NewStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" New" rerender="contactForm">
                                        <apex:param name="myParam" value="New"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!WorkingStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Working" rerender="contactForm">
                                        <apex:param name="myParam" value="Working"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ResolvedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Resolved" rerender="contactForm">
                                        <apex:param name="myParam" value="Resolved"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ClosedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Closed" rerender="contactForm">
                                        <apex:param name="myParam" value="Closed"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!CancelledStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Cancelled" rerender="contactForm">
                                        <apex:param name="myParam" value="Cancelled"/>
                                    </apex:commandLink>
                                </li>
                                <li id="last">
                                    ({!ReopenedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Reopened" rerender="contactForm">
                                        <apex:param name="myParam" value="Reopened"/>
                                    </apex:commandLink>
                                </li>
                            </ul>
                            <h5>
                                TICKETS
                            </h5> 
                            <table width="95%" border="1" cellpadding="5">
                                <tr align="left">
                                    <th style="width:25px;">Ticket#</th>
                                    <th style="width:200px;">Subject</th>
                                    <th>Description</th>
                                    <th style="width:50px;">Status</th>
                                    <th style="width:75px;"></th>
                                </tr>
                                <apex:repeat value="{!tickets}" var="ticket">
                                    <tr>
                                        <td>{!ticket.Ticket_Number__c}</td>
                                        <td>{!ticket.Name}</td>
                                        <td>{!ticket.Description__c}</td>
                                        <td>{!ticket.Status__c}</td>
                                        <td><apex:outputLink value="/detail?id={!projId}&ticketId={!ticket.Id}">View Details</apex:outputLink></td>
                                    </tr>
                                </apex:repeat>
                            </table>
                            <apex:outputPanel rendered="{!(tickets.empty == false)}" styleClass="pagination" >
                                <ul>
                                    <li><apex:commandLink id="first" value="First" action="{!first}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="prev" value="Prev" action="{!previous}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="next" value="Next" action="{!next}" rendered="{!hasNext}" /></li>
                                    <li><apex:commandLink id="last" value="Last" action="{!last}" rendered="{!hasNext}" /></li>
                                    <li><apex:outputText value="Page {!pageNumber} of {!totalPages}" /></li>
                                </ul>
                            </apex:outputPanel>
                        </apex:form>
                    </apex:outputPanel>                     
                </div>
        </div>

ありがとう。

4

1 に答える 1

0

1 つの SOQL クエリですべてのステータスの各ステータスの数を取得できます。

[select status__c, count(id) from Ticket__c Where Project__c =: projId group by status__c]

次に、既存のゲッターを介して結果を公開し、クエリ結果を公開して、リピーターを介して UI にバインドできます。

于 2013-03-06T21:07:05.393 に答える