You need to sign in to do that
Don't have an account?
Saurabh Sood 12
Datatable send only active page value into controller
Hi everyone,
Created a page with datatable pagination and add checkbox with help of wrapper class the problem is
When I check some checkbox active and inactive page with help of navigation of datatable and select command button it only send current active page value to controller.
Controller
public class AccountSearchController1 {
public Account accNew {
get;
set;
}
public Account acc {
get;
set;
}
public boolean isOwner {
get;
set;
}
public list < wrapAccount > wrapperList {
get;
set;
}
public list < wrapAccount > selectedRecord {
get;
set;
}
public List < Account > accList = new List < Account > ();
Map <id,Account> SelectedAccountMap = new Map <id,Account>();
public List < Account > accountList {
get;
set;
}
public list < Account > changeOwnerList {
get;
set;
}
public integer LimitSize = 500;
// create a list of strings to hold the conditions
List < string > conditions = new List < string > ();
public AccountSearchController1() {
system.debug('==>AccountDynamicQuery is calling==>');
selectedRecord = new list < wrapAccount > ();
accNew = new Account();
acc = new Account();
accountList = new List < Account > ();
// cc = new list < wrapAccount > ();
changeOwnerList = new List < Account > ();
isOwner = true;
wrapperList = new List<wrapAccount>();
}
public void accSearch() {
accountList.clear();
conditions.clear();
SelectedAccountMap.clear();
wrapperList.clear();
searchAccounts();
}
public Void searchAccounts() {
String strQuery = 'SELECT Id,Name,AccountNumber From Account';
if (acc.Name != null && acc.Name != '') {
string name = acc.Name + '%' ;
conditions.add('Name Like : name');
}
if (acc.AccountNumber != null && acc.AccountNumber != '') {
conditions.add('AccountNumber Like\'%' + acc.AccountNumber + '%\' ');
}
if (conditions.size() > 0) {
strQuery += ' WHERE ' + conditions[0];
for (Integer i = 1; i < conditions.size(); i++)
strQuery += ' AND ' + conditions[i];
}
// add sort and limits at the end
strQuery += ' ORDER BY Name ASC LIMIT :LimitSize';
system.debug('Query string '+ strQuery);
accountList = Database.query(strQuery);
getSelectedItem();
for (Account a: accountList){
if(SelectedAccountMap.ContainsKey(a.id))
{
wrapperList.add(new wrapAccount(a, true));
}
else
{
wrapperlist.add(new wrapAccount(a,false));
}
}
}
public void getSelectedItem(){
if(wrapperList != null){
for(wrapAccount cc: wrapperList){
if (cc.isSelected == true)
{
SelectedAccountMap.put(cc.acc.id,cc.acc);
}
else
{
SelectedAccountMap.remove(cc.acc.id);
}
}
}
}
public void changeOwner() {
getSelectedItem();
changeOwnerList = SelectedAccountMap.values();
}
//wrapper account start
public class wrapAccount {
public Account acc {
get;
set;
}
public boolean isSelected {
get;
set;
}
public wrapAccount(account a, boolean b) {
acc = a;
isSelected = b;
}
} //wrapper end
}
Page
<apex:page controller="AccountSearchController1" >
<apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" />
<apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" />
<apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
<apex:actionstatus id="counterStatus">
<apex:facet name="start">
<div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb; height:100%;opacity:0.65;width:100%;">
<div class="waitingHolder" style="top: 100px; width: 91px;">
<img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
<span class="waitingDescription">Loading...</span>
</div>
</div>
</apex:facet>
</apex:actionstatus>
<apex:form id="theform" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!acct.Name}" />
<apex:inputField value="{!acct.AccountNumber}" />
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!accSearch}" value="search" status="counterStatus" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock title="Customers Details" rendered="{!if(wrapperlist != null && wrapperlist.size > 0 , true, false)}" >
<apex:pageBlockButtons location="top" >
<apex:commandButton value="Change Owner" action="{!changeOwner}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!wrapperlist}" var="a" id="accTable">
<apex:column >
<apex:inputCheckbox value="{!a.isSelected}">
<apex:param assignTo="{!wrapperList}" value="{! a.isSelected}" />
</apex:inputCheckbox>
</apex:column>
<apex:column value="{!a.acc.Name}"/>
<apex:column value="{!a.acc.AccountNumber}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageblock title="Customer details" rendered="{!if(changeOwnerList != null && changeOwnerList.size > 0 , true ,false)}" >
<!-- <apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputlabel for="owner">New Owner</apex:outputlabel>
<apex:inputfield id="owner" value="{!accNew.Name}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>-->
<apex:pageBlockSection title="Show Customers" columns="1" collapsible="false" >
<apex:pageBlockTable value="{!changeOwnerList}" var="o" >
<apex:column value="{!o.name}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!ownerSave}" reRender="theform" status="counterStatus" />
<apex:commandButton value="Cancel" action="{!cancelBack}" immediate="true" reRender="theform" status="counterStatus" />
</apex:pageBlockButtons>
</apex:pageblock>
<script>
j$ = jQuery.noConflict();
j$(document).ready( function () {
var contactTable = j$('[id$="accTable"]').DataTable({
stateSave: true
});
});
</script>
</apex:form>
</apex:page>
Created a page with datatable pagination and add checkbox with help of wrapper class the problem is
When I check some checkbox active and inactive page with help of navigation of datatable and select command button it only send current active page value to controller.
Controller
public class AccountSearchController1 {
public Account accNew {
get;
set;
}
public Account acc {
get;
set;
}
public boolean isOwner {
get;
set;
}
public list < wrapAccount > wrapperList {
get;
set;
}
public list < wrapAccount > selectedRecord {
get;
set;
}
public List < Account > accList = new List < Account > ();
Map <id,Account> SelectedAccountMap = new Map <id,Account>();
public List < Account > accountList {
get;
set;
}
public list < Account > changeOwnerList {
get;
set;
}
public integer LimitSize = 500;
// create a list of strings to hold the conditions
List < string > conditions = new List < string > ();
public AccountSearchController1() {
system.debug('==>AccountDynamicQuery is calling==>');
selectedRecord = new list < wrapAccount > ();
accNew = new Account();
acc = new Account();
accountList = new List < Account > ();
// cc = new list < wrapAccount > ();
changeOwnerList = new List < Account > ();
isOwner = true;
wrapperList = new List<wrapAccount>();
}
public void accSearch() {
accountList.clear();
conditions.clear();
SelectedAccountMap.clear();
wrapperList.clear();
searchAccounts();
}
public Void searchAccounts() {
String strQuery = 'SELECT Id,Name,AccountNumber From Account';
if (acc.Name != null && acc.Name != '') {
string name = acc.Name + '%' ;
conditions.add('Name Like : name');
}
if (acc.AccountNumber != null && acc.AccountNumber != '') {
conditions.add('AccountNumber Like\'%' + acc.AccountNumber + '%\' ');
}
if (conditions.size() > 0) {
strQuery += ' WHERE ' + conditions[0];
for (Integer i = 1; i < conditions.size(); i++)
strQuery += ' AND ' + conditions[i];
}
// add sort and limits at the end
strQuery += ' ORDER BY Name ASC LIMIT :LimitSize';
system.debug('Query string '+ strQuery);
accountList = Database.query(strQuery);
getSelectedItem();
for (Account a: accountList){
if(SelectedAccountMap.ContainsKey(a.id))
{
wrapperList.add(new wrapAccount(a, true));
}
else
{
wrapperlist.add(new wrapAccount(a,false));
}
}
}
public void getSelectedItem(){
if(wrapperList != null){
for(wrapAccount cc: wrapperList){
if (cc.isSelected == true)
{
SelectedAccountMap.put(cc.acc.id,cc.acc);
}
else
{
SelectedAccountMap.remove(cc.acc.id);
}
}
}
}
public void changeOwner() {
getSelectedItem();
changeOwnerList = SelectedAccountMap.values();
}
//wrapper account start
public class wrapAccount {
public Account acc {
get;
set;
}
public boolean isSelected {
get;
set;
}
public wrapAccount(account a, boolean b) {
acc = a;
isSelected = b;
}
} //wrapper end
}
Page
<apex:page controller="AccountSearchController1" >
<apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" />
<apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" />
<apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
<apex:actionstatus id="counterStatus">
<apex:facet name="start">
<div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb; height:100%;opacity:0.65;width:100%;">
<div class="waitingHolder" style="top: 100px; width: 91px;">
<img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
<span class="waitingDescription">Loading...</span>
</div>
</div>
</apex:facet>
</apex:actionstatus>
<apex:form id="theform" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!acct.Name}" />
<apex:inputField value="{!acct.AccountNumber}" />
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!accSearch}" value="search" status="counterStatus" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock title="Customers Details" rendered="{!if(wrapperlist != null && wrapperlist.size > 0 , true, false)}" >
<apex:pageBlockButtons location="top" >
<apex:commandButton value="Change Owner" action="{!changeOwner}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!wrapperlist}" var="a" id="accTable">
<apex:column >
<apex:inputCheckbox value="{!a.isSelected}">
<apex:param assignTo="{!wrapperList}" value="{! a.isSelected}" />
</apex:inputCheckbox>
</apex:column>
<apex:column value="{!a.acc.Name}"/>
<apex:column value="{!a.acc.AccountNumber}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageblock title="Customer details" rendered="{!if(changeOwnerList != null && changeOwnerList.size > 0 , true ,false)}" >
<!-- <apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputlabel for="owner">New Owner</apex:outputlabel>
<apex:inputfield id="owner" value="{!accNew.Name}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>-->
<apex:pageBlockSection title="Show Customers" columns="1" collapsible="false" >
<apex:pageBlockTable value="{!changeOwnerList}" var="o" >
<apex:column value="{!o.name}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!ownerSave}" reRender="theform" status="counterStatus" />
<apex:commandButton value="Cancel" action="{!cancelBack}" immediate="true" reRender="theform" status="counterStatus" />
</apex:pageBlockButtons>
</apex:pageblock>
<script>
j$ = jQuery.noConflict();
j$(document).ready( function () {
var contactTable = j$('[id$="accTable"]').DataTable({
stateSave: true
});
});
</script>
</apex:form>
</apex:page>