This is my first post .. Please Help me. Problem is i can update my selected data .. but search and filter fields are not working .. Please guide me how can i bind my wrap class with page reference search and filter..
Apex Controller
public class SController { public List wrapList {get; set;} public Boolean selected {get; set;} public list Accounts; public string finalSearchValue{get;set;} public string fullname{get;set;} public List Add{get;set;} public list search{get;set;} public list Remove{get;set;} public string value {get;set;} public string Option{get;set;} public SController() { Accounts = [select Id, Name, Active__c, Phone from Account]; if(wrapList == null) { wrapList = new List(); for(Account a: Accounts) { wrapList.add(new wrapData(a)); } } } public pagereference AddStatus() { Add = new List(); for(wrapData ch : wrapList) { if(ch.selected == true && ch.ac.Active__c=='No') { ch.ac.Active__c='Yes'; Add.add(ch.ac); } } update Add; return null; } public pagereference RemoveStatus() { Remove = new List(); for(wrapData ch : wrapList) { if(ch.selected == true && ch.ac.Active__c=='Yes') { ch.ac.Active__c='No'; Remove.add(ch.ac); } } update Remove; return null; } public pagereference Search() { String finalSearchValue = '%' + fullname + '%'; Accounts = [Select Id, Name, Active__c FROM Account where Name like :finalSearchValue]; return null; } public List getOptions() { List Option = new List(); Option.add(new selectOption('none','None')); Option.add(new selectOption('y','Active Accounts')); Option.add(new selectOption('n','Inactive Accounts')); Option.add(new selectOption('c','All Accounts')); return Option; } public void FetchData(string opt) { Option = opt; if(opt=='y') { Accounts = [Select Id, Name, Active__c FROM Account where Active__c = 'Yes' ]; } else if(opt=='n') { Accounts = [Select Id, Name, Active__c FROM Account where Active__c = 'No']; } else if(opt == 'c' || opt =='none') { Accounts = [Select Id, Name, Active__c FROM Account]; } } public pagereference Filter() { List Option = new List(); FetchData(value); return null; } public class wrapData { public Account us {get; set;} public Boolean selected {get; set;} public wrapData(Account a) { ac = a; selected = false; } } }
<apex:page controller="SController"> <script type="text/javascript"> function selectAllCheckboxes(ch,receivedInputID) { var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++) { if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1) { inputCheckBox[i].checked = ch.checked; } } } </script> <apex:form > <apex:pageBlock > <apex:pageBlockButtons location="top" > <apex:commandButton value="Inactive Account" action="{!RemoveStatus}" /> <apex:commandButton value="Active Account" action="{!AddStatus}" /> </apex:pageBlockButtons> <table> <tr> <td> <apex:selectList value="{!Value}" size="1"> <apex:selectOptions value="{!Options}"/> </apex:selectList></td> <td><apex:commandButton value="filter" action="{!filter}"/></td> <td><apex:inputText value="{!fullname}" html-placeholder="Search" /></td> <td><apex:commandButton value="search" action="{!Search}" /></td></tr></table> <apex:pageBlockTable value="{!wrapList}" var="Wrap"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/> </apex:facet> <apex:inputCheckbox value="{!Wrap.selected}" id="inputId"/> </apex:column> <apex:column headerValue="Full Name" value="{!Wrap.ac.Name}" /> <apex:column headerValue="Phone" value="{!Wrap.ac.Phone}" /> <apex:column headerValue="Status" value="{!Wrap.ac.Active__c}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>