function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sunila MSunila M 

Sort pageblocktable data without query

Hi All,

 I have used a pageBlockTable to display my list of data. As I have to show the data from 2 custom object I have used List of Map instead of list of sObject. Now my requirement is to sort the table data on column click.

Could you please share the solution with sample code to sort a pageblocktable without any query.
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Sunila,

sorting columns in page block table.
<apex:page standardController="Opportunity" tabStyle="Opportunity" extensions="myext" id="thepage">
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"/>
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"/>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" type="text/css" media="all" />
    <apex:includeScript value="{!URLFOR($Resource.tablesorter, 'jquery.tablesorter.min.js')}"/>

    <script type="text/javascript">
        $j = jQuery.noConflict();    
        $j(document).ready(function () {
        $j("[id$=theaddrs]").tablesorter();
        });    
    </script>

    <apex:pageBlock id="theaddrsblock">
        <apex:pageBlockTable value="{!Addrs}" var="a" id="theaddrs" styleClass="tablesorter" headerClass="header">
            <apex:column>
                <apex:facet name="header">
                    <apex:outputText styleClass="header" value="{!$ObjectType.Address__c.Fields.Street__c.Label}" />
                </apex:facet>
                <apex:outputText value="{!a.Street__c}" />
            </apex:column>
        <!-- the other columns, closing tags, and that's it -->

Please refer the below link for reference. Hope it will be helpful.

Thanks
Rahul