Page:
<apex:page controller="SelectedAccountsWrapperController" >
<apex:form id="pg" >
<apex:panelGrid columns="2" width="100%" id="pgr">
<apex:pageblock title="Available Records" id="Available_PBS">
<apex:pageBlockSection Title="List of Available Records">
<apex:dataTable value="{!ServicesList}" var="s" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column headerValue="Action">
<apex:inputCheckbox value="{!s.selected}" id="checkedone">
<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS"/>
</apex:inputCheckbox>
</apex:column>
<apex:column headervalue="Name" value="{!s.sr.Name}" />
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageblock>
<apex:pageblock title="Selected Records" id="bloc">
<apex:pageBlockSection Title="List of Selected Records" id="Selected_PBS" >
<apex:dataTable value="{!RServicesList}" var="ss" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column headervalue="Name" value="{!ss.rsr.Name}" />
<apex:column headervalue="Industry" value="{!ss.rsr.Industry}" />
<apex:column headerValue="Action" >
<apex:inputCheckbox value="{!ss.Rselected}" id="checkedone" >
<apex:actionSupport event="onclick" action="{!RemoveSelected}" rerender="Selected_PBS,Available_PBS,pg,bloc"/>
</apex:inputCheckbox>
</apex:column>
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:panelGrid>
</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 SelectedAccountsWrapperController{
public List<Servicewrapper> ServicesList {get;set;}
public list<RServicewrapper> RServicesList {get;set;}
List<Servicewrapper> selectedServices = new List<Servicewrapper>();
List<RServicewrapper> RselectedServices = new List<RServicewrapper>();
List<Servicewrapper> Services {get;set;}
public SelectedAccountsWrapperController(){
ServicesList = new List<Servicewrapper>();
RServicesList = new list<RServicewrapper>();
for(Account a : [select Id, Name, Industry from Account Where Industry!=null order by Name asc]){
Servicewrapper sw = new Servicewrapper();
sw.sr = a;
sw.selected = false;
ServicesList.add(sw);
}
}
public PageReference getSelected()
{
selectedServices.clear();
RServicesList.clear();
for(Servicewrapper srwrapper: ServicesList)
if(srwrapper.selected == true){
rServicewrapper swobj =new rServicewrapper ();
swobj.rsr = srwrapper.sr;
swobj.rselected = true;
RServicesList.add(swobj);
}
system.debug('selectedServices++++'+selectedServices);
return null;
}
public List<Servicewrapper> GetSelectedRecords()
{
if(selectedServices.size()>0){
return selectedServices;
}
else
return null;
}
public PageReference RemoveSelected() {
for(RServicewrapper rsrwrapper: RServicesList){
for(Servicewrapper srwrapper: ServicesList){
if(rsrwrapper.Rselected == false){
if(srwrapper.sr.id== rsrwrapper.rsr.id){
srwrapper.selected = false;
}
}
}
}
List<RServicewrapper> tempServices = new List<RServicewrapper>();
for(RServicewrapper rsrwrapper: RServicesList){
if(rsrwrapper.Rselected == true){
tempServices.add(rsrwrapper);
}
}
RServicesList = tempServices;
return null;
}
public class Servicewrapper
{
public Account sr{get; set;}
public Boolean selected {get; set;}
}
public class RServicewrapper
{
public Account rsr {get; set;}
public Boolean Rselected {get; set;}
}
}
No comments:
Post a Comment