You need to sign in to do that
Don't have an account?
Apex Page Message: count of checkboxes selected
I have a pageBlockTable with inputcheckbox. I want to count the number of records selected and display the count in the ApexPages.message.
Any idea how I can do this? Thanks!!
VFP
<apex:pageBlockTable value="{!priceist}" var="p" id="results">
<apex:column >
<apex:inputCheckbox value="{!p.selected}" onchange="updateSelectCount(this);"/>
</apex:column>
<apex:column >
...
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
//Apex class
public PageReference approveRecord(){
// my logic and finally
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Confirm,'All records successfully approved!')); // Here instead of 'All' i want {!count}
}
Hi,
The Other way is to use the jQuery to count the number of checkboxes.
$("input:checkbox:checked").length;
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Regards,
Arun.
Can someone please check what i am doing worng when concatenating the countofapprovedrecords to the Apexpage message?
As suggested by @vbs, I am iterating through the list, checking if record.selected = true and adding to the counter.
My debug statement, shows me the number of selected records.
I am converting the integer to a string (debugs show correct converted value) and using this string in my Apex.messages, howver, the message doesn't display the string that i converted from ineteger value.
public integer countapprovedrecords=0;
for (myWrapper record : IncList){
if(record.selected){
countapprovedrecords++;
}
}
if (!Apexpages.hasMessages()){
string countstring = string.valueof(countapprovedrecords);
system.debug('integer converted to string' +countstring);
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Confirm,'countstring'+ 'records successfully approved!'));
}
Hi,
Try this one. countrstring shouldn't within single quotes.
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Confirm, countstring+ 'records successfully approved!'));
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Regards,
Arun.
Thanks!! that was it.
Thanks to everyone.. All the responses were helpful.