Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

Checkbox in DataTable

Be First!
by April 14, 2012 APEX, JAVASCRIPT, Visual Force
Displaying the check box in a data table or page block table is a general requirement in every project. with the help of wrapper class we can display the checkboxes in a data table. For the select all checkbox we need to add small javascript so that if we select the header checkbox it will select all the checkboxes.
Apex Class:

public class Checkbox_Class  { 
    List accountList = new List();
    List selectedAccounts = new List();       
    public List getAccounts()  {
        for(Account a: [select Id, Name, AccountNumber, Phone from Account limit 5])
        accountList.add(new accountwrapper(a));
        return accountList;
    }
   
    public PageReference getSelected()   {
        selectedAccounts.clear();
        for(accountwrapper accwrapper: accountList)
        if(accwrapper.selected == true)
        selectedAccounts.add(accwrapper.acc);
        return null;
    }
   
    public List GetSelectedAccounts()  {
        if(selectedAccounts.size()>0)
        return selectedAccounts;
        else
        return null;
    }  
   
    public class accountwrapper  {
        public Account acc{get; set;}
        public Boolean selected {get; set;}
        public accountwrapper(Account a)
        {
            acc = a;
            selected = false;
        }
    }
}

VisualForce Page:












a.acc.Name}” />














Demo : https://sfdevforce-developer-edition.na12.force.com/vfCheckbox

(1046)

Previous
Next

Leave a Reply