You need to sign in to do that
Don't have an account?

How to display selected records(check box) of one page block table in another pageblocktable?
Hi i want to develop a page block table with all the account records ,each record contains a checkbox in the pageblocktable ,when a user check/select some records on the table and press show selected button it need to display selected records in another pageblocktable. i am new to this and i am in learning stage.i have referred http://wiki.developerforce.com/page/Wrapper_Class but the example wont work . I have developed visualforce code but confused with the adding controller and wrapperclass.can any one help me plsss.. Thanks&Regards Veer
Hi,
Try the below code snippet as reference:
..............................
Page
..............................
<apex:page controller="page11" >
<apex:form >
<apex:pageBlock Title="Account with CheckBoxes">
<apex:pageBlockSection Title="List of Available Account">
<apex:dataTable value="{!Accounts}" var="a" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column >
<apex:facet name="header"> <apex:inputCheckbox >
<apex:actionSupport event="onclick" action="{!GetSelected}" onsubmit="checkAll(this)" rerender="Selected_PBS"/>
</apex:inputCheckbox></apex:facet>
<apex:inputCheckbox value="{!a.selected}" id="checkedone">
<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS" />
</apex:inputCheckbox></apex:column>
<apex:column headervalue="Account Name" value="{!a.cont.Name}" />
<apex:column headervalue="Account Number" value="{!a.cont.accountnumber}" />
</apex:dataTable>
</apex:pageBlockSection>
<Apex:pageBlockSection >
</Apex:pageBlockSection>
<apex:pageBlockSection Title="Selected Account" id="Selected_PBS">
<apex:dataTable value="{!SelectedAccounts}" var="s" columnswidth="50px,50px" cellpadding="4" border="1"> <apex:param name="v2" value="{!s.id}" assignTo="{!id2}" />
<apex:column headervalue="Account Name" value="{!s.Name}" />
<apex:column headervalue="Account Number" value="{!s.accountnumber}" />
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script>
function checkAll(cb)
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf("checkedone")!=-1)
inputElem[i].checked = cb.checked;
}
}
</script>
</apex:page>
..............................
Controller
..............................
public class page11 {
public list<Account> con;
public String str{get;set;}
public String id2 { get; set; }
List<Accountwrapper> AccountList{get;set;}
List<Account> selectedAccounts = new List<Account>();
public List< Account> f{get;set;}
public String name { get; set; }
public String id { get; set; }
public String param1{get;set;}
public List<Accountwrapper> getAccounts()
{
AccountList=new List<Accountwrapper >();
param1=ApexPages.currentPage().getParameters().get('v1');
for(Account a : [select Id, Name,AccountNumber from Account where id =:param1 limit 5])
AccountList.add(new Accountwrapper(a));
return AccountList;
}
public PageReference getSelected()
{
selectedAccounts.clear();
for(Accountwrapper conwrapper : AccountList)
if(conwrapper.selected == true)
{
selectedAccounts.add(conwrapper.cont);
}
return null;
}
public List<Account> GetSelectedAccounts()
{
if(selectedAccounts.size()>0)
return selectedAccounts;
else
return null;
}
public class Accountwrapper
{
public Account cont{get; set;}
public Boolean selected {get; set;}
public Accountwrapper(Account a)
{
cont = a;
selected = false;
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Public list<Contact> conlst{get; set;}
public list<wrpcon> conw{get; set;}
public ContactwrEx()
{
conw =new list<wrpcon>();
if(conw != null)
{
for(Contact cn:[select Id,LastName,Phone from Contact limit 5])
{
conw.add(new wrpcon(cn));
}
}
}
public void chkselected()
{
conlst=new list<Contact>();
for(wrpcon cw : conw)
{
if(cw.s == true)
{
conlst.add(cw.con);
}
}
}
public class wrpcon{
public Contact con{get; set;}
public boolean s{get; set;}
public wrpcon(Contact c)
{
con=c;
s=false;
}
}
}
vfpage
<apex:page controller="ContactwrEx" sidebar="false">
<script type="text/avascript">
function chkselected(obj,recid)
{
var inputcheckbox = document.getelementsbytagname("input");
for(var i=0; i<inputcheckbox.length; i++){
if(inputcheckbox[i].id.indexOf(recid)!=-1){
inputcheckbox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Show Selected Contacts" action="{!chkselected}" rerender="table2"/>
</apex:pageBlockButtons>
<apex:pageblockSection title="All Contacts" collapsible="false" columns="2">
<apex:pageBlockTable value="{!conw}" var="cc" id="table" title="All Contacts">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="chkselected(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!cc.s}" id="inputId"/>
</apex:column>
<apex:column value="{!cc.con.lastName}" />
<apex:column value="{!cc.con.Phone}" />
</apex:pageBlockTable>
<apex:pageBlockTable value="{!conlst}" var="c" id="table2" title="Selected Contacts">
<apex:column value="{!c.LastName}" headerValue="contact Name"/>
<apex:column value="{!c.Phone}" headerValue="Phone"/>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>