You need to sign in to do that
Don't have an account?
TehNrd
Issues with select All checkbox and header data binding
I'm am trying to create a simple selectAll check box at the top of my table but I can not figure out why this is not working. It's as if the data binding is not occurring when the check box is located in the header section of the table. If I remove the check box from the table it works fine.
This uses standard fields so it should be easy to copy and paste to reproduce.
Thanks,
Jason
This uses standard fields so it should be easy to copy and paste to reproduce.
Code:
Page:
<apex:page>
<c:resellerAccountSearch />
</apex:page>
Component:
<apex:component controller="resellerAccountSearch" >
<apex:form >
<apex:pageblock >
<apex:inputText value="{!searchValue}" id="searchtext"/>
<apex:commandButton value="Search" action="{!search}" rerender="results" status="search"/>
<br/>
<!-- This check box works fine but if it is in the header section below it doesn't work
<apex:inputCheckBox value="{!selectAllCheckbox}">
<apex:actionSupport event="onclick" action="{!selectAll}" rerender="results"/>
</apex:inputCheckBox> -->
<apex:actionStatus id="search">
<apex:facet name="start">
<strong>Retrieving data... </strong>
</apex:facet>
<apex:facet name="stop">
<apex:pageblockTable value="{!cAccounts}" var="c" id="results">
<apex:column >
<apex:facet name="header">
<apex:inputCheckBox value="{!selectAllCheckbox}">
<apex:actionSupport event="onclick" action="{!selectAll}" rerender="results"/>
</apex:inputCheckBox>
</apex:facet>
<apex:inputCheckBox value="{!c.selected}"/>
</apex:column>
<apex:column value="{!c.acct.Name}"/>
<apex:column value="{!c.acct.BillingCity}"/>
<apex:column value="{!c.acct.CreatedDate}"/>
<apex:column value="{!c.acct.LastModifiedDate}"/>
<apex:column value="{!c.acct.Id}"/>
</apex:pageblockTable>
</apex:facet>
</apex:actionStatus>
</apex:pageblock>
</apex:form>
</apex:component>
Controller:
public class resellerAccountSearch {
public String searchValue {get; set;}
public List<Account> results {get; set;}
public List<cAccount> cAccounts {get; set;}
public Boolean selectAllCheckbox {get; set;}
//Constructor
public resellerAccountSearch(){
results = new List<Account>();
cAccounts = new List<cAccount>();
}
public PageReference search(){
results.clear();
cAccounts.clear();
if(searchValue.length() > 1){
searchValue = '*'+searchValue+'*';
List<List<SObject>> searchList = [FIND :searchValue IN NAME FIELDS RETURNING Account(Id, Name, BillingCity, CreatedDate, LastModifiedDate order by LastModifiedDate desc )];
results = ((List<Account>)searchList[0]);
for(Account acct: results){
cAccounts.add(new cAccount(acct));
}
}
return null;
}
public PageReference selectAll(){
system.debug(selectAllCheckbox);
for(cAccount acct : cAccounts){
system.debug(acct.selected);
if(selectAllCheckbox == true){
acct.selected = true;
}else{
acct.selected = false;
}
}
return null;
}
public class cAccount{
public Account acct {get; set;}
public Boolean selected {get; set;}
public cAccount(Account a){
this.acct = a;
selected = false;
}
}
}
Thanks,
Jason
I just did the same yesterday and in fact i had to introduce a small javascript function on the "onclick" event of the "select all check box".
The first thing i did is to add an Id to the InputCheckBox :
Then i created this small javascript function :
Finally i plugged this function to the onclick event of the select all check box :
It works quite good.
Hope this can help you.
Catherin.
I try to stay away from Javascript and use apex as much as possible but thanks for the workaround. I must admit it is quicker though.
Message Edited by TehNrd on 12-16-2008 02:46 PM