You need to sign in to do that
Don't have an account?
JosephJ
sorting on column
Hi,
I need to implement Sorting in my Visualforce Page on column. I've used my Custom Controller Class to Display records in apex : pageBlockTable, but I'm not able to implement sorting there.Please help.
Thanks in advance
James
<apex:page standardController="Task" extensions="TaskSearchController">
<apex:form id="searchForm">
<apex:PageBlock mode="inlineEdit">
<apex:pageblockSection id="searchBlockSection">
<apex:pageBlockSectionItem id="searchBlockSectionItem">
<apex:outputLabel >Keyword</apex:outputLabel>
<apex:panelGroup >
<apex:inputtext id="searchTextBox" value="{!searchText}"> </apex:inputtext>
<apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search"> </apex:commandButton>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageblockSection>
<apex:actionStatus id="status" startText="Searching... please wait..."/>
<apex:pageBlocksection id="renderBlock" >
<apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
<apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
<apex:column value="{!o.Subject}"/>
<apex:outputLink value="/{!o.Id}">{!o.Status}</apex:outputLink>
<apex:column value="{!o.Status}"/>
</apex:pageblocktable>
</apex:pageBlocksection>
</apex:pageblock>
</apex:form>
<apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>
// Apex
public class TaskSearchController
{
public apexpages.standardController controller{get;set;}
public Task l;
public List<Task> searchResults {get; set; }
public string searchText
{
get
{
if (searchText==null) searchText = '';
return searchText;
}
set;
}
public TaskSearchController(ApexPages.StandardController controller)
{
this.controller = controller;
this.l = (Task) controller.getRecord();
}
public PageReference search()
{
if(SearchResults == null)
{
SearchResults = new List<Task>();
}
else
{
SearchResults.Clear();
}
String qry = 'Select Id,Subject,Status,ActivityDate from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status,ActivityDate';
// System.debug(qry);
SearchResults = Database.query(qry);
// System.debug(SearchResults);
return null;
}
}
I need to implement Sorting in my Visualforce Page on column. I've used my Custom Controller Class to Display records in apex : pageBlockTable, but I'm not able to implement sorting there.Please help.
Thanks in advance
James
<apex:page standardController="Task" extensions="TaskSearchController">
<apex:form id="searchForm">
<apex:PageBlock mode="inlineEdit">
<apex:pageblockSection id="searchBlockSection">
<apex:pageBlockSectionItem id="searchBlockSectionItem">
<apex:outputLabel >Keyword</apex:outputLabel>
<apex:panelGroup >
<apex:inputtext id="searchTextBox" value="{!searchText}"> </apex:inputtext>
<apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search"> </apex:commandButton>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageblockSection>
<apex:actionStatus id="status" startText="Searching... please wait..."/>
<apex:pageBlocksection id="renderBlock" >
<apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
<apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
<apex:column value="{!o.Subject}"/>
<apex:outputLink value="/{!o.Id}">{!o.Status}</apex:outputLink>
<apex:column value="{!o.Status}"/>
</apex:pageblocktable>
</apex:pageBlocksection>
</apex:pageblock>
</apex:form>
<apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
</apex:page>
// Apex
public class TaskSearchController
{
public apexpages.standardController controller{get;set;}
public Task l;
public List<Task> searchResults {get; set; }
public string searchText
{
get
{
if (searchText==null) searchText = '';
return searchText;
}
set;
}
public TaskSearchController(ApexPages.StandardController controller)
{
this.controller = controller;
this.l = (Task) controller.getRecord();
}
public PageReference search()
{
if(SearchResults == null)
{
SearchResults = new List<Task>();
}
else
{
SearchResults.Clear();
}
String qry = 'Select Id,Subject,Status,ActivityDate from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status,ActivityDate';
// System.debug(qry);
SearchResults = Database.query(qry);
// System.debug(SearchResults);
return null;
}
}
try this: SearchResults = Database.query(qry);
searchResults.sort(); // just add this line you may get your desired result.
Thanks
Rishav
All Answers
try this: SearchResults = Database.query(qry);
searchResults.sort(); // just add this line you may get your desired result.
Thanks
Rishav
do you want to sort a particular column?