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
HeenaHeena 

Sorting in a data table

Hi,

 

I am trying to build the same sorting functionality we have in the Enhanced list view in a data table in my visualforce page. 

 

When the user clicks on the column the data is sorted wrt that column. My trouble is this data is coming from a webservice and is stored in form of arrays of a custom class instead of some object in salesforce. How do i perform the sort. 

 

Does visualforce or apex have any standard function or class to sort data. Or will i have to implement some sorting algorithm to do this.

 

Thanks,

Heena

Adil_SFDCAdil_SFDC

Hi 

 

Did you by any chance got to the solution . Please share asap as I am stuck at a point where i recieve documents from Website on VF Page and i want to sort that descending. 

 

Adil

Aamir khan 19Aamir khan 19
Hi Adil,
Below is the code to sort the data in table.
If you click on particular column it will sort the data.

<apex:page standardController="Account" >

<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" />
<apex:includeScript value="//cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.17.8/js/jquery.tablesorter.min.js"/>
<apex:stylesheet value="//cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.17.8/css/theme.green.css"/>

<script>
  $(document).ready(function()
  {
    $("[id$='accsTable']").tablesorter({theme: 'green'});
  });
</script>

<apex:datatable value="{!account}" var="acc" id="accsTable" >
  <apex:column headerValue="Created">
    <apex:outputText value="{0, date, dd/MM/yyyy}">
      <apex:param value="{!acc.CreatedDate}" />
    </apex:outputText>
  </apex:column>
  <apex:column headerValue="Name">
    <apex:outputField value="{!acc.Name}" />
  </apex:column>
  <apex:column headerValue="Street">
    <apex:outputField value="{!acc.BillingStreet}" />
  </apex:column>
  <apex:column headerValue="City">
    <apex:outputField value="{!acc.BillingCity}" />
  </apex:column>
  <apex:column headerValue="State">
    <apex:outputField value="{!acc.BillingState}" />
  </apex:column>
  <apex:column headerValue="Postcode">
    <apex:outputField value="{!acc.BillingPostalCode}" />
  </apex:column>
</apex:datatable>
</apex:page>


Hope this will resolve your Que. :-)