select all checkbox in visualforce using action function
Here is an example that demonstrates select all checkbox column using action function. Though the response is slower, at times we may need to use this depending on requirement.
Visualforce Page
Apex Class
Visualforce Page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| <apex:page controller= "checkAllcolumnDemocontroller" > <!-- check all columns demo page using action function - it has slow respose--> <apex:form > <apex:pageblock id= "pgblck" > <apex:pageblocktable value= "{!WrapperList}" var = "wraprec" > <apex:column value= "{!wraprec.accRec.name}" /> <apex:column value= "{!wraprec.accRec.accountnumber}" /> <apex:column value= "{!wraprec.accRec.annualrevenue}" /> <apex:column > <apex:facet name= "header" > <apex:inputCheckbox onclick= "selectall()" /> </apex:facet> <apex:inputCheckbox value= "{!wraprec.checkflag}" /> </apex:column> </apex:pageblocktable> </apex:pageblock> <apex:actionFunction name= "selectallmethod" action= "{!selectallnone}" rerender= "pgblck" /> </apex:form> //<script type="text/javascript"> function selectall() { selectallmethod(); } // |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| Public with sharing class checkAllcolumnDemocontroller { Public List<wrapperclass> wrapList {get;set;} Public boolean checked{get;set;} Public checkAllcolumnDemocontroller(){ checked = false ; } Public void selectallnone(){ if (!checked) checked = true ; else checked = false ; } Public List<wrapperclass> getWrapperList(){ wrapList = New List<wrapperclass>(); for (Account acc:[Select name,accountnumber,id,annualrevenue,description from account limit 5]){ if (!checked) wrapList.add(New wrapperclass(acc, false )); else wrapList.add(New wrapperclass(acc, true )); } return wrapList; } Public class wrapperclass{ Public account accRec{get;set;} Public boolean checkFlag{get;set;} Public wrapperclass(account acc,boolean flag){ accRec = acc; checkFlag = flag; } } } |
No comments:
Post a Comment