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

How to apply search interface to the list of wrapper class?What should we write in search function....
want to search below the name from below list dynamicalyy;
Here is the controller
public with sharing class Sim_EventOfficeContactsController {
public List<OfficeContactWrapper> officeContacts {get;set;}
private List<Office_Contact__c> toBeDeleted{get;set;}
public Integer selectedIndex{get;set;}
private Integer index{get;set;}
private String eventId;
public id eventAccountid;
public String searchstr{get;set;}
public Sim_EventOfficeContactsController(ApexPages.StandardController controller) {
toBeDeleted = new List<Office_Contact__c>();
eventId = controller.getId();
List<Event_and_Lecture__c> eventList = [select id,account__r.Id from Event_and_Lecture__c where id = :eventId limit 1];
eventAccountid = eventList[0].account__r.Id;
system.debug('eventAccountid: '+eventAccountid);
initOfficeContacts();
}
public pagereference dosearch(){
String strg = '%'+searchstr+'%';
=[SELECT id,name FROM Office_Contact__c WHERE name like:strg];
return null;
}
public boolean getHasContacts(){
return officeContacts.size()>0;
}
//methods for getting list of contacts
public void initOfficeContacts()
{
officeContacts = new List<OfficeContactWrapper>();
index = 1;
//if viewing on standard controller (account), add in filter for accountId
for(Office_Contact__c officeContact : [SELECT id, name,Event_and_Lecture__c,email__c,CORE_Referral_Manager__c ,Phone__c, account__c, Type__c, Preferences__c
FROM Office_Contact__c WHERE account__c = :eventAccountid ORDER BY Name asc LIMIT 1000]){
OfficeContactWrapper ocw = new OfficeContactWrapper(officeContact,index);
officeContacts.add(ocw);
index++;
}
}
//save all records that were updated
public void save()
{
List<Office_Contact__c> toUpsert = new List<Office_Contact__c>();
for(OfficeContactWrapper ocw: officeContacts){
toUpsert.add(ocw.officeContact);
}
upsert toUpsert;
delete toBeDeleted;
initOfficeContacts();
}
public void add()
{
Office_Contact__c ref = new Office_Contact__c(Event_and_Lecture__c = eventId, account__c = eventAccountid);
officeContacts.add(new OfficeContactWrapper(ref,index));
index++;
}
public void delRow()
{
integer index = 0;
System.debug('rowIndex for delete'+ selectedIndex);
for(OfficeContactWrapper ocw: officeContacts){
if(ocw.rowIndex == selectedIndex){
if(ocw.officeContact.Id != null)
toBeDeleted.add(ocw.officeContact);
break;
}
index++;
}
officeContacts.remove(index);
save();
}
class OfficeContactWrapper{
public Office_Contact__c officeContact{get;set;}
public Integer rowIndex{get;set;}
public OfficeContactWrapper(Office_Contact__c officeContact,Integer rowIndex){
this.officeContact = officeContact;
this.rowIndex = rowIndex;
}
}
}