• Nizar Saleh
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello,

I have a PageBlockTable, with few columns, one of them being Checkbox. I want to have a feature like "select/deselect Al"l and Save All.
User-added image

User-added image
 
<apex:page Controller="GestionDeProduit" sidebar="false" showHeader="false" >
    <script type="text/javascript" language="javascript">  
    function checkJS(id1,id2)
    {        
        var v1 ='';
        var v2 ='';
        if(document.getElementById(id1) != null){
            v1 = document.getElementById(id1).value;
        }     
        if(document.getElementById(id2) != null){
            v2 = document.getElementById(id2).value;
        }
        checkAF(v1,v2); 
    }     
    </script> 
    <apex:form id="products">  
        <apex:actionFunction name="checkAF" action="{!updateRow}" reRender="panelRefresh">
            <apex:param name="check1" value="" />
            <apex:param name="check2" value="" />
        </apex:actionFunction>         
        <apex:outputPanel id="panelRefresh" >
            <apex:outputPanel >
                <apex:pageBlock >
                    <apex:pageBlockTable value="{!productList}" var="item">
                        <apex:column headerValue="Products" >
                            <apex:outputText value="{!item.Product__r.Name}"/>
                        </apex:column>
             
                        <apex:column headerValue="Disponibilite" >
                            <apex:inputField value="{!item.Availability__c }" id="availabilityId" onchange="checkJS('{!$Component.availabilityId}','{!$Component.primaryId}');"/>
                            <apex:inputHidden value="{!item.Name }" id="primaryId"/>
                        </apex:column>                          
                    </apex:pageBlockTable> 
                </apex:pageBlock>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:form>
</apex:page>

public with sharing class GestionDeProduit {
    transient public List<Product_Availability__c> productList{get;set;}
    
    public GestionDeProduit(){
        init();
    }
    
    public void init(){
        try{
              productList = [SELECT  Name, Availability__c
                               FROM Product_Availability__c];   
        }Catch(QueryException de ){
            System.debug(de);
        } 
    }
    
    public void updateRow(){
        String temp2 = System.currentPageReference().getParameters().get('check2');
        List<Product_Availability__c> pList = new List<Product_Availability__c>();
        try{
            pList = [SELECT  Name, Availability__c
                     FROM Product_Availability__c WHERE Name =:temp2];
        }Catch(QueryException de ){
            System.debug(de);
        }               
        if(pList.size()>0){
            if(pList[0].Availability__c == true){
                pList[0].Availability__c = false;
            }else if(pList[0].Availability__c == false){
                pList[0].Availability__c = true;
            }
            try{
                update pList[0];
            }Catch(DMLException de ){
                System.debug(de);
            }              
        }
        init();         
    }    
    
 
}

Thank you
  • July 29, 2015
  • Like
  • 0