You need to sign in to do that
Don't have an account?
VARALAXMI JANGAY
Sort the values of Custom Setting Data in pageBlockTable
Hi,
Below is the code of custom Setting Data with the sorting the values in the pageBlockTable,
Sort order is not working, Below is my code.
Please can anyone help me,
<apex:page controller="CustomSettingsCon">
<apex:form>
<apex:pageBlock id="pageBlock">
<apex:pageBlockButtons location="top">
<apex:commandButton value="View" action="{!ViewData}" id="theButton" rerender="pageBlock"></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!codes}" var="c" rendered="{!NOT(ISNULL(codes))}" >
<apex:column >
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort">
<apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
<apex:outputLink value="/{!c.Id}" target="_blank">{!c.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!c.Phone_Number__c}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Phone_Number__c{!IF(sortExpression=='Phone_Number__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Phone_Number" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!c.Address__c}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Address__c{!IF(sortExpression=='Address__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Address" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!c.Email__c}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Email__c{!IF(sortExpression=='Email__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Email__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
===============
public class CustomSettingsCon {
public List<Account__c> codes{get;set;}
private String sortDirection = 'ASC';
private String sortExp = 'name';
public String sortExpression{
get
{
return sortExp;
}
set
{
//if the column is clicked on then switch between Ascending and Descending modes
if (value == sortExp)
sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
else
sortDirection = 'ASC';
sortExp = value;
}
}
public String getSortDirection()
{
//if not column is selected
if (sortExpression == null || sortExpression == '')
return 'ASC';
else
return sortDirection;
}
public void setSortDirection(String value){
sortDirection = value;
}
public List<Account__c> getcodes(){
return codes;
}
public void ViewData(){
string sortFullExp = sortExpression + ' ' + sortDirection;
Map<String,Account__c> allcodes = Account__c.getAll();
codes = allCodes.values();
}
}
Thanks,
Varalaxmi
Below is the code of custom Setting Data with the sorting the values in the pageBlockTable,
Sort order is not working, Below is my code.
Please can anyone help me,
<apex:page controller="CustomSettingsCon">
<apex:form>
<apex:pageBlock id="pageBlock">
<apex:pageBlockButtons location="top">
<apex:commandButton value="View" action="{!ViewData}" id="theButton" rerender="pageBlock"></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!codes}" var="c" rendered="{!NOT(ISNULL(codes))}" >
<apex:column >
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort">
<apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
<apex:outputLink value="/{!c.Id}" target="_blank">{!c.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!c.Phone_Number__c}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Phone_Number__c{!IF(sortExpression=='Phone_Number__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Phone_Number" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!c.Address__c}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Address__c{!IF(sortExpression=='Address__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Address" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!c.Email__c}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Email__c{!IF(sortExpression=='Email__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Email__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
===============
public class CustomSettingsCon {
public List<Account__c> codes{get;set;}
private String sortDirection = 'ASC';
private String sortExp = 'name';
public String sortExpression{
get
{
return sortExp;
}
set
{
//if the column is clicked on then switch between Ascending and Descending modes
if (value == sortExp)
sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
else
sortDirection = 'ASC';
sortExp = value;
}
}
public String getSortDirection()
{
//if not column is selected
if (sortExpression == null || sortExpression == '')
return 'ASC';
else
return sortDirection;
}
public void setSortDirection(String value){
sortDirection = value;
}
public List<Account__c> getcodes(){
return codes;
}
public void ViewData(){
string sortFullExp = sortExpression + ' ' + sortDirection;
Map<String,Account__c> allcodes = Account__c.getAll();
codes = allCodes.values();
}
}
Thanks,
Varalaxmi
here i post snap of my code use works fine for me
and here is the sorting utility class
if this was helpfull please mark as best answer else let me know ......
Thank you
Avaneesh Singh