You need to sign in to do that
Don't have an account?
How to show selected accounts in another pageblock table??
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..
<apex:page standardController="Account" recordSetVar="Account" extensions="MyAccountListCntrlr" > <apex:form > <apex:pageBlock title="MyPageBlock1" > <apex:pageBlockButtons > <apex:commandButton value="Show Selected Accounts" action="{!displaySelectedAccountNumbers}"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="2"> <apex:pageBlockTable value="{!account}" var="s" title="All Accounts" > <apex:column headerValue="active" > <apex:inputCheckbox /> </apex:column> <apex:column value="{!s.Name}" /> <apex:column value="{!s.Phone}" /> </apex:pageBlockTable> <!--<apex:pageBlockTable value="{!account}" var="s" title="Selected Accounts" align="right"> </apex:pageBlockTable>--> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
i did'nt understand how to select selected accounts and pass them to next table when show selected button clicked.
Thanks&Regards
Veer
Hi,
Try the below code snippet as reference:
..............................
Page
..............................
<apex:page controller="page11" >
<apex:form >
<apex:pageBlock Title="Contacts with CheckBoxes">
<apex:pageBlockSection Title="List of Available Contacts">
<apex:dataTable value="{!contacts}" 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="First Name" value="{!a.cont.FirstName}" />
<apex:column headervalue="Last Name" value="{!a.cont.LastName}" />
<apex:column headervalue="Email" value="{!a.cont.Email}" />
</apex:dataTable>
</apex:pageBlockSection>
<Apex:pageBlockSection >
</Apex:pageBlockSection>
<apex:pageBlockSection Title="Selected Contacts" id="Selected_PBS">
<apex:dataTable value="{!SelectedContacts}" var="s" columnswidth="50px,50px" cellpadding="4" border="1"> <apex:param name="v2" value="{!s.id}" assignTo="{!id2}" />
<apex:column headervalue="First Name" value="{!s.FirstName}" />
<apex:column headervalue="Last Name" value="{!s.LastName}" />
<apex:column headervalue="Email" value="{!s.Email}" />
</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<Contact> con;
public String str{get;set;}
public String id2 { get; set; }
List<contactwrapper> contactList{get;set;}
List<contact> selectedContacts = new List<contact>();
public List< Contact> f{get;set;}
public String name { get; set; }
public String id { get; set; }
public String param1{get;set;}
public List<contactwrapper> getContacts()
{
contactList=new List<contactwrapper >();
param1=ApexPages.currentPage().getParameters().get('v1');
for(contact a : [select Id, Name,Email,FirstName,LastName from Contact where account.id =:param1 limit 5])
contactList.add(new contactwrapper(a));
return contactList;
}
public PageReference getSelected()
{
selectedContacts.clear();
for(contactwrapper conwrapper : contactList)
if(conwrapper.selected == true)
{
selectedContacts.add(conwrapper.cont);
}
return null;
}
public List<Contact> GetSelectedContacts()
{
if(selectedContacts.size()>0)
return selectedContacts;
else
return null;
}
public class contactwrapper
{
public Contact cont{get; set;}
public Boolean selected {get; set;}
public contactwrapper(Contact 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.
All Answers
Hi,
Try the below code snippet as reference:
..............................
Page
..............................
<apex:page controller="page11" >
<apex:form >
<apex:pageBlock Title="Contacts with CheckBoxes">
<apex:pageBlockSection Title="List of Available Contacts">
<apex:dataTable value="{!contacts}" 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="First Name" value="{!a.cont.FirstName}" />
<apex:column headervalue="Last Name" value="{!a.cont.LastName}" />
<apex:column headervalue="Email" value="{!a.cont.Email}" />
</apex:dataTable>
</apex:pageBlockSection>
<Apex:pageBlockSection >
</Apex:pageBlockSection>
<apex:pageBlockSection Title="Selected Contacts" id="Selected_PBS">
<apex:dataTable value="{!SelectedContacts}" var="s" columnswidth="50px,50px" cellpadding="4" border="1"> <apex:param name="v2" value="{!s.id}" assignTo="{!id2}" />
<apex:column headervalue="First Name" value="{!s.FirstName}" />
<apex:column headervalue="Last Name" value="{!s.LastName}" />
<apex:column headervalue="Email" value="{!s.Email}" />
</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<Contact> con;
public String str{get;set;}
public String id2 { get; set; }
List<contactwrapper> contactList{get;set;}
List<contact> selectedContacts = new List<contact>();
public List< Contact> f{get;set;}
public String name { get; set; }
public String id { get; set; }
public String param1{get;set;}
public List<contactwrapper> getContacts()
{
contactList=new List<contactwrapper >();
param1=ApexPages.currentPage().getParameters().get('v1');
for(contact a : [select Id, Name,Email,FirstName,LastName from Contact where account.id =:param1 limit 5])
contactList.add(new contactwrapper(a));
return contactList;
}
public PageReference getSelected()
{
selectedContacts.clear();
for(contactwrapper conwrapper : contactList)
if(conwrapper.selected == true)
{
selectedContacts.add(conwrapper.cont);
}
return null;
}
public List<Contact> GetSelectedContacts()
{
if(selectedContacts.size()>0)
return selectedContacts;
else
return null;
}
public class contactwrapper
{
public Contact cont{get; set;}
public Boolean selected {get; set;}
public contactwrapper(Contact 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.
Hi ankit,
Thanks for your reply it is very usefull to me ,i have doubt in the below code what is v1 in get method
param1=ApexPages.currentPage().getParameters().get('v1');
Thanks&Regards
veer
Thanks ankit you helped me a lot dude.