2017-10-02 61 views
0

ページ作成中に選択したチェックボックスを保持する方法と、下のコードを使用して選択リスト内の別の値を選択する方法を知りたい方。ありがとうございました! :)ページング中に選択したチェックボックスを保持する

ここに私が使った拡張機能があります。これにはテーブルが含まれ、値とページ設定が選択されます。

//for season status 
public void Stats(){    
    this.RaceEntries= 0; 
    this.TotDis= 0; 
    this.hasError = false; 

    for(TrackWrapper tw : twList){   
      if(tw.isChecked){    
        if(this.RaceEntries<=12 && this.TotDis<=300){ 
         this.RaceEntries++; 
         this.TotDis += tw.tra.Length__c; 
        } 

        if(this.RaceEntries > 12){ 
         this.hasError = true; 
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Race Entries exceeded. 12 tracks per season only.')); 
        } 
        if(this.TotDis > 300){ 
         this.hasError = true; 
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Distance exceeded. 300KM per season only.')); 
        }         
       } 

       //List<TrackWrapper> tempList = new List<TrackWrapper>(); 


    } 

    this.RemRace= 12 - this.RaceEntries; 
    this.RemDis= 300 - this.TotDis;    
    } 

    //Populate the table from the Selected value in selectlist 
    public void searchRecords(){ 
    trackList= new List<Track__c>(); 
    if(selectValue != null){ //If the selectvalue has a value 
     OffsetSize = 0;         
     this.twList= new List<TrackWrapper>(); 
     trackList= Database.query('SELECT Name, Location__c, Difficulty__c, Length__c from Track__c WHERE Difficulty__c LIKE : selectValue LIMIT :LimitSize OFFSET :OffsetSize');    


     for(Track__c t : this.trackList) { 
      TrackWrapper tw = new TrackWrapper(); 
      tw.tra = t; 
      tw.isChecked = false; 
      this.twList.add(tw); 
      } 

     //for TotalPage Numbers per selected value 
     Integer totalSelect = database.countQuery('select count() from Track__c WHERE Difficulty__c LIKE : selectValue'); 
     Integer totDiv = totalSelect /5; 
     Integer remain = math.mod(totalSelect, 5); 

      if(remain!= 0){ 
       this.totalPage = totDiv + 1;     
      } else{ 
       this.totalPage = totDiv; 
      } 

      currentPage = 1;     
      buttonDisable();     

    }else if(selectValue == null){ // If the selectvalue is null        
     this.twList= new List<TrackWrapper>(); 
     trackList= Database.query('SELECT Name, Location__c, Difficulty__c, Length__c from Track__c LIMIT :LimitSize OFFSET :OffsetSize');   

     for(Track__c t : this.trackList) { 
      TrackWrapper tw = new TrackWrapper(); 
      tw.tra = t; 
      tw.isChecked = false; 
      this.twList.add(tw);    
     }    

      //for TotalPage Numbers per selected value 
     Integer total = database.countQuery('select count() from Track__c'); 
     Integer tot = total/5; 
     Integer rem = math.mod(total, 5); 

      if(rem!= 0){ 
       this.totalPage = tot + 1;     
      }else{ 
       this.totalPage = tot; 
      }  
      buttonDisable(); 
    }   
    }   

//for pagination 
public integer totalRecs; 
public integer OffsetSize{get;set;} 
public integer LimitSize= 5;  

public boolean isFirstPage {get;set;} 
public boolean isLastPage {get;set;}  

public Integer currentPage {get;set;} 
public Integer totalPage {get;set;}   
public Integer remainder {get;set;} 

public void buttonDisable(){ 
    this.isFirstPage = false; 
    this.isLastPage = false; 

    if(currentPage == 1){ 
     this.isFirstPage = true; 
    } 

    if(currentPage == totalPage) { 
     this.isLastPage = true; 
    } 
    } 

    // PAGINATION 
    public void FirstPage(){ 
    OffsetSize = 0; 
    searchRecords(); 
    this.currentPage = 1;  
    buttonDisable(); 
    }  

    public void previous(){ 
    OffsetSize = OffsetSize - LimitSize;  
    searchRecords(); 
    this.currentPage--;  
    buttonDisable();   
    } 

    public void next(){   
    OffsetSize = OffsetSize + LimitSize;  
    searchRecords(); 
    this.currentPage++;     
    buttonDisable();   
    } 

    public void LastPage(){ 
    totalRecs = [select count() from track__c]; 
    OffsetSize = totalrecs - math.mod(totalRecs,LimitSize); 
    searchRecords(); 
    this.currentPage = this.totalPage; 
    buttonDisable();  
    } 

これは私が使用したVisualForceです。また、テーブル、選択リスト、ページネーションも含まれます。

<apex:pageBlockSection title="Season Stats" id="stat">              
      <apex:outputText label="Race Entries" value="{!RaceEntries}" /> 
      <apex:outputText label="Total Distance" value="{!TotDis}"/> 
      <apex:outputText label="Remaining Race Entries" value="{!RemRace}"/> 
      <apex:outputText label="Remaining Distance" value="{!RemDis}"/>   
     </apex:pageBlockSection>  

     <apex:actionRegion >   
     <apex:pageBlockSection id="details" title="Tracks" columns="1">  
      <apex:outputLabel value="Track Difficulty Level Filter" />   
       <apex:selectList size="1" value="{!selectValue}">     
        <apex:selectOption itemValue="" itemLabel="All" />            
        <apex:selectOptions value="{!statusOptions}" />          
        <apex:actionSupport event="onchange" action="{!searchRecords}" rerender="details" status="waitStatus"/> 
       </apex:selectList>  

       <apex:outputPanel id="out"> 
        <apex:actionStatus id="waitStatus">  
         <apex:facet name="start"> 
          <apex:outputPanel > 
           <apex:outputText >Updating...</apex:outputText> 
           <apex:image value="https://shop.usa.canon.com/estore/marketing/maxify/redesign/maxify-loader.gif" title="Processing..." height="20px"/>   
          </apex:outputPanel> 
         </apex:facet> 
        </apex:actionstatus> 
       </apex:outputPanel>       

       <apex:outputPanel ><br/> 
        <apex:pageBlocktable value="{!twList}" var="track" id="table">    
         <apex:column HeaderValue="Select">       
          <apex:inputCheckbox value="{!track.isChecked}">  
          <apex:actionSupport event="onchange" rerender="stat, messages, btnsave" action="{!Stats}" status="waitStatus"/> 
          </apex:inputCheckbox>                                                      
         </apex:column> 
         <apex:column value="{!track.tra.Name}" HeaderValue="Track Name"/> 
         <apex:column value="{!track.tra.Location__c}" HeaderValue="Location"/> 
         <apex:column value="{!track.tra.Difficulty__c}" HeaderValue="Difficulty"/> 
         <apex:column value="{!track.tra.Length__c}" HeaderValue="Circuit Length (KM)"/> 
       </apex:pageBlocktable> 
       </apex:outputPanel> 

     <!-- Pagination --> 
      <center> 
       <apex:pageBlockSection columns="1"> 
       <apex:panelGrid columns="6">     
         <center> 
         <apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!isFirstPage}" /> 
         <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!isFirstPage}"/> 
         Page {!currentPage} of {!totalPage} 
         <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!isLastPage}" /> 
         <apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!isLastPage}" /> 
         </center> 
       </apex:panelGrid> 
       </apex:pageBlockSection> 
      </center> 
     </apex:pageBlockSection>    
     </apex:actionRegion>    

答えて

0

あなたは、その後、前ページネーションにメモリ内の現在の値を格納するために地図を使用し、ページ区切りの後に戻っマップから値を取得する必要があります。たとえば:

Map<Id,trackWrapper> trackMap = new Map<Id,trackWrapper>(); 

public next(){ 
    for (trackWrapper t : twList){ 
    trackMap.put(t.tra.id, t); 
    } 
    //paginate method 
    for (trackWrapper t : twList){ 
    if (trackMap.containsKey(t.tra.id)){ 
     t.isChecked = trackMap.get(t.tra.id).isChecked; 
    } 
    } 
} 
+0

これは動作しません –

+0

何がうまくいかない、詳細を提供できますか?コメント「// paginateメソッド」がどこにあるかをあなたのページネートメソッドと呼びましたか? –

関連する問題