You need to sign in to do that
Don't have an account?
Harsha Shri
Pagination for wrapper Search results
Hi All,
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
01<apex:page controller="CategorySearchController">
02 <apex:form >
03 <apex:pageBlock >
04
05 <apex:pageBlockButtons >
06 <apex:commandButton action="{!back}" value="Back"/>
07 </apex:pageBlockButtons>
08 <apex:pageMessages />
09
10 <apex:pageBlockSection title="You Selected" columns="1">
11 <apex:pageBlockTable value="{!selectedCategories}" var="c">
12 <apex:column value="{!c.cat.Name}"/>
13 </apex:pageBlockTable>
14 </apex:pageBlockSection>
15
16 </apex:pageBlock>
17 </apex:form>
18</apex:page>
controller class
01public class CategorySearchController {
02
03 // the results from the search. do not init the results or a blank rows show up initially on page load
04 public List<categoryWrapper> searchResults {get;set;}
05 // the categories that were checked/selected.
06 public List<categoryWrapper> selectedCategories {
07 get {
08 if (selectedCategories == null) selectedCategories = new List<categoryWrapper>();
09 return selectedCategories;
10 }
11 set;
12 }
13
14 // the text in the search box
15 public string searchText {
16 get {
17 if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use
18 return searchText;
19 }
20 set;
21 }
22
23 // constructor
24 public CategorySearchController() {}
25
26 // fired when the search button is clicked
27 public PageReference search() {
28
29 if (searchResults == null) {
30 searchResults = new List<categoryWrapper>(); // init the list if it is null
31 } else {
32 searchResults.clear(); // clear out the current results if they exist
33 }
34 // Note: you could have achieved the same results as above by just using:
35 // searchResults = new List<categoryWrapper>();
36
37 // dynamic soql
38 String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name';
39
40 for(account c : Database.query(qry)) {
41 //new wrapper by passing it the category in the constructor
42 CategoryWrapper cw = new CategoryWrapper(c);
43 // wrapper to the results
44 searchResults.add(cw);
45 }
46 return null;
47 }
48
49 public PageReference next() {
50
51 // clear out the currently selected categories
52 selectedCategories.clear();
53
54 // add the selected categories to a new List
55 for (CategoryWrapper cw : searchResults) {
56 if (cw.checked)
57 selectedCategories.add(new CategoryWrapper(cw.cat));
58 }
59
60 // ensure they selected at least one category or show an error message.
61 if (selectedCategories.size() > 0) {
62 return Page.Category_Results;
63 } else {
64 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.'));
65 return null;
66 }
67
68 }
69
70 // fired when the back button is clicked
71 public PageReference back() {
72 return Page.Category_Search;
73 }
74
75}
01public class CategoryWrapper {
02
03 public Boolean checked{ get; set; }
04 public account cat { get; set;}
05
06 public CategoryWrapper(){
07 cat = new account ();
08 checked = false;
09 }
10
11 public CategoryWrapper(account c){
12 cat = c;
13 checked = false;
14 }
15
16
17
18}
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
01<apex:page controller="CategorySearchController">
02 <apex:form >
03 <apex:pageBlock >
04
05 <apex:pageBlockButtons >
06 <apex:commandButton action="{!back}" value="Back"/>
07 </apex:pageBlockButtons>
08 <apex:pageMessages />
09
10 <apex:pageBlockSection title="You Selected" columns="1">
11 <apex:pageBlockTable value="{!selectedCategories}" var="c">
12 <apex:column value="{!c.cat.Name}"/>
13 </apex:pageBlockTable>
14 </apex:pageBlockSection>
15
16 </apex:pageBlock>
17 </apex:form>
18</apex:page>
controller class
01public class CategorySearchController {
02
03 // the results from the search. do not init the results or a blank rows show up initially on page load
04 public List<categoryWrapper> searchResults {get;set;}
05 // the categories that were checked/selected.
06 public List<categoryWrapper> selectedCategories {
07 get {
08 if (selectedCategories == null) selectedCategories = new List<categoryWrapper>();
09 return selectedCategories;
10 }
11 set;
12 }
13
14 // the text in the search box
15 public string searchText {
16 get {
17 if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use
18 return searchText;
19 }
20 set;
21 }
22
23 // constructor
24 public CategorySearchController() {}
25
26 // fired when the search button is clicked
27 public PageReference search() {
28
29 if (searchResults == null) {
30 searchResults = new List<categoryWrapper>(); // init the list if it is null
31 } else {
32 searchResults.clear(); // clear out the current results if they exist
33 }
34 // Note: you could have achieved the same results as above by just using:
35 // searchResults = new List<categoryWrapper>();
36
37 // dynamic soql
38 String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name';
39
40 for(account c : Database.query(qry)) {
41 //new wrapper by passing it the category in the constructor
42 CategoryWrapper cw = new CategoryWrapper(c);
43 // wrapper to the results
44 searchResults.add(cw);
45 }
46 return null;
47 }
48
49 public PageReference next() {
50
51 // clear out the currently selected categories
52 selectedCategories.clear();
53
54 // add the selected categories to a new List
55 for (CategoryWrapper cw : searchResults) {
56 if (cw.checked)
57 selectedCategories.add(new CategoryWrapper(cw.cat));
58 }
59
60 // ensure they selected at least one category or show an error message.
61 if (selectedCategories.size() > 0) {
62 return Page.Category_Results;
63 } else {
64 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.'));
65 return null;
66 }
67
68 }
69
70 // fired when the back button is clicked
71 public PageReference back() {
72 return Page.Category_Search;
73 }
74
75}
01public class CategoryWrapper {
02
03 public Boolean checked{ get; set; }
04 public account cat { get; set;}
05
06 public CategoryWrapper(){
07 cat = new account ();
08 checked = false;
09 }
10
11 public CategoryWrapper(account c){
12 cat = c;
13 checked = false;
14 }
15
16
17
18}
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
You can refer to these blogs where proper example is mentioned :
1. http://amitsalesforce.blogspot.in/2014/11/pagination-with-wrapper-class-with.html
2. http://sfdcsharepoint.com/wrapper-class-pagination-salesforce/ (http://amitsalesforce.blogspot.in/2014/11/pagination-with-wrapper-class-with.html)
Hope this helps you.
Thanks,
Pankaj.
Thank you for your response.
I want pagination for dynamic results from search. That is how I have in my code. In your example the pagination is for the data which is coming directly form object.
If you have any code suggestion for my existing code please suggest me