0

I have a page with bootstrap Checkbox. The select All is working fine, however each row wise select check box is not working properly. only first row checkbox is selected and unselected. If I click on any other row check box, it will check the first row checkbox only.

    <table id="domainTable"> <!-- Added ID -->
<thead>
<tr>
   <th>         
         <div class="checkbox checkbox-primary">
           <input type="checkbox" name="selectAll" id="selectAllDomainList" checked=""/>
               <label for="selectAllDomainList">
                            Select All
                        </label>
         </div>
    </th>
</tr>
</thead>
<tbody>
     <apex:variable value="{!1}" var="rowNum"/> 
          <apex:repeat value="{!wrapList}" var="e">  
               <tr> 
                  <td> 
                      <div class="checkbox checkbox-primary">
                                    <input id="Text{!rowNum}" type="checkbox" checked=""/>
                                    <label for="Text{!rowNum}">
                                        Primary
                                    </label>
                                </div>
                            </td>                                                                                                                         
                  <td><apex:outputText value="{!e.eng.name}" /></td>   
                        </tr>                                             
             <apex:variable var="rowNum" value="{! rowNum + 1 }"/> 
       </apex:repeat>
</tbody>

JQuery:

<script>

  // on document ready
    jQuery(function($){  

        $('#selectAllDomainList').click (function () {
             var checkedStatus = this.checked;
            $('#domainTable tbody tr').find('td:first :checkbox').each(function () {
                $(this).prop('checked', checkedStatus);
             });
        });
    });

Class:

    public class assignStudentsTest1 {
 public String selectedSite  {get;set;}
 public String assignUassign  {get;set;}
 public String selectedTrack  {get;set;}
 public String selectedCohort  {get;set;}
 public list<Account> accList { get; set; }
 public String globalselectedLC  {get;set;}
 public String globalselectedTrack {get;set;}
 public boolean itFailed  {get;set;}
 public boolean globalUpdate  {get;set;}
 public String assignment {get;set;}
 public Integer count{get;set;}
 public List<SelectOption> cohortOptions {get;set;}
 public List<Track_Specialities__c> trackSpecialities {get;set;}
 public List<SelectOption> siteOptions {get;set;}
 public List<SelectOption> assignUassignOptions {get;set;}
 public List<SelectOption> trackOptions {get;set;}
 public List<SelectOption> Lcoptions{get;set;} 
 public List<Engagement__c> Enagements{get;set;}
 public List<WrapperClass> wrapList{get;set;}
 public Map<String,String> lcOptionsMap {get;set;}
 public assignStudentsTest1 ()
 {
      accList = New list<Account> ();
        accList = [Select Id, Name from Account];
    itFailed = false;
    selectedCohort = '';
    cohortOptions = new List<SelectOption>();
    cohortOptions.add(new SelectOption('--None--','--None--'));
    for(cohort__c obj :[SELECT Id, Name FROM cohort__c] )
    {
        cohortOptions.add(new SelectOption(obj.Name,obj.Name));
    }
    selectedSite = '';
    siteOptions = new List<SelectOption>();
    siteOptions.add(new SelectOption('--None--','--None--'));
    for(Site__c obj :[SELECT Id, Name FROM Site__c] )
    {
        siteOptions.add(new SelectOption(obj.Name,obj.Name));
    }
    assignUassign = '';
    assignUassignOptions = new List<SelectOption>();
    assignUassignOptions.add(new SelectOption('--None--','--None--'));
    assignUassignOptions.add(new SelectOption('Assigned','Assigned'));
    assignUassignOptions.add(new SelectOption('Unassigned','Unassigned'));    
    lcOptionsMap = new Map<String,String>();  
    Lcoptions = new List<SelectOption>();
    Lcoptions.add(new SelectOption('','--Unassigned--'));

    selectedTrack = '';
    trackOptions = new List<SelectOption>();
    trackOptions.add(new SelectOption('--None--','--None--'));
    Schema.DescribeFieldResult fieldResult = Learning_Community__c.Track__c.getDescribe();
    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();        
    for( Schema.PicklistEntry f : ple)
       {
          trackOptions.add(new SelectOption(f.getLabel(), f.getValue()));
       }  
 }

 public List<Track_Specialities__c> getTrackspecialities(String eId){
     trackSpecialities = new List<Track_Specialities__c>();
     trackSpecialities = [SELECT Id,Name,Product__r.Name,Track_Familiy__c from Track_Specialities__c WHERE Engagement__c=:eId];
     return trackSpecialities;
 }
 public void getEngagements(){
     //lcOptionslist();
     if(wrapList!=null)
     wrapList.clear();     
     integer i=0;       
     wrapList = new list<WrapperClass>();        
     String Query= 'SELECT id, Name, Site__c,Track_Assignment__c,Sample__c, Learning_Community__c,Cohort__c,Learning_Community__r.Name FROM Engagement__c WHERE (Cohort__c=:selectedCohort AND Site__c=:selectedSite)';        
        if(assignUassign=='Unassigned'){            
            Query += ' AND Learning_Community__c=null';  
        }else if(assignUassign=='Assigned'){            
            Query += ' AND Learning_Community__c!=null';  
            System.debug('Query '+Query );
        }

     for(Engagement__c eng : Database.query(Query)){  
            if(eng.Learning_Community__c==null){            
                wrapList.add(new WrapperClass(eng,trackOptions,'--None--',Lcoptions,'--Unassigned--',i,getTrackspecialities(eng.id))); 
                System.debug('wrapList '+wrapList);           
            } else{            
                wrapList.add(new WrapperClass(eng,trackOptions,eng.Track_Assignment__c,Lcoptions,eng.Learning_Community__c,i,getTrackspecialities(eng.id)));   
            }           
            i++;
        } 
 }

 public void refreshPage(){ 
 itFailed = false;     
     for(WrapperClass wr: wrapList){
        if (wr.rowcount==count && wr.selectedLC!='' || wr.selectedLC!=null){                
            wr.selectedLC = lcOptionsMap.get(wr.selectedLC);  
        }else if (wr.rowcount==count && wr.selectedNTrack!='--None--'){
            wr.selectedNTrack = wr.selectedNTrack; 
        }       
     }
 }
 public void applyGlobalchanges(){  
     itFailed = false;     
     for(WrapperClass wr: wrapList){     
         if ((globalselectedLC!=null || globalselectedTrack!=null) && wr.selected!=false){ 
             wr.selectedLC = globalselectedLC; 
             wr.selectedNTrack = globalselectedTrack;       
         }          
     }      
 }
 public Pagereference lcOptionslist(){              
     for(Learning_Community__c obj :[SELECT Id, Name 
                                     FROM Learning_Community__c 
                                     WHERE Cohort__c=:selectedCohort  
                                    ])
       {
         Lcoptions.add(new SelectOption(obj.Id,obj.Name));
         lcOptionsMap.put(obj.Id,obj.Name);
         System.debug('lcOptionsMap '+lcOptionsMap);            
       }
     return null;
 }
 public pagereference updateEngagements(){
 try{ 
     list<Engagement__c> enList=new list<Engagement__c>(); 
     for(WrapperClass wr: wrapList){ 
        if(wr.selectedLC!='' && wr.selectedLC!=null){  
             Engagement__c en= new Engagement__c();
             en.id = wr.eng.Id; 
             en.Learning_Community__c= wr.selectedLC; 
             en.Track_Assignment__c = wr.selectedNTrack; 
             System.debug('enList '+en);
             enList.add(en);             
         }                     
     } 
     if(enList.size()>0){
         itFailed = true;   
         update enList;         
         }
     }
     catch(exception e){
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value ' +e.getMessage()));
     } 
     return null;
 }

 public class WrapperClass{
        public Engagement__c eng {get; set;}
        public List<SelectOption> selectedTrack{get; set;}
        public String selectedNTrack{get; set;}
        public List<SelectOption> selectedCLC{get; set;}
        public String selectedLC{get; set;}
        public integer rowcount{get;set;}
        public boolean selected{get;set;}
        public List<Track_Specialities__c> trackSList{get;set;}
        public WrapperClass(Engagement__c e,List<SelectOption> track, String s,List<SelectOption> clc, String lc, integer r,List<Track_Specialities__c> ts){
            selectedTrack = track;
            eng = e;
            selectedNTrack = s;
            selectedCLC = clc;
            selectedLC = lc;
            rowcount = r;
            selected = false;
            trackSList = ts;
        }
    }
}

Problem:

<apex:repeat value="{!accList}" var="e">  (Working fine)
<apex:repeat value="{!wrapList}" var="e">  (Not Working)

If I use "accList" (singleList) the selectAll checkbox is working fine. However if I use wrapperList, SelectAll checkbox function (Jquery) is not working.

Select All is working with accList

enter image description here

Select All not working with WrapList

enter image description here

4
  • First para single checkbox not working. In last para your select all is not working. Can you confirm what exactly not working with you Commented Oct 22, 2016 at 19:07
  • @TusharSharma, It is working if I pass just "accList" (Account List), where as if I pass "wrapperList" and click on "Select All" check box, it will not select all the checkboxes, it will only select "Select All" check box. Sorry if I am confusing you.
    – Ajay
    Commented Oct 22, 2016 at 19:10
  • do me a favor and post the code with wrapper list so that we can check if you missed anything Commented Oct 22, 2016 at 19:13
  • @TusharSharma: Added entire class and also the screenshot which is not working
    – Ajay
    Commented Oct 22, 2016 at 19:22

1 Answer 1

0

Found the issue in command button rerender. If I remove the rerender it is working. I need to see how I can rerender the table now.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .