Wednesday, January 21, 2015

Salesforce - Using Jquery DataTable for pagination and sorting in visualforce page

<apex:page showHeader="false" sidebar="false" controller="ControllerName"  standardStylesheets="false">
    
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css"></link>    
    <apex:includeScript value="https://code.jquery.com/jquery-1.11.1.min.js"/>
    <apex:includeScript value="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"/>    
    <apex:includeScript value="https://code.jquery.com/jquery-1.10.2.min.js"/>
    <apex:includeScript value="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.js"/> 
      
    <apex:form >       
        <table id="projectTable" class="table-project" >
            <thead>
            <tr>                     
                <th> Project Name </th>                        
            </tr>
            </thead>
            <tbody>
// projectList - is controller List
            <apex:repeat value="{!projectList}" var="pro">
                <tr>                    
                    <td>
                            {!pro.Name}                       
                    </td>
                   
                </tr>
            </apex:repeat>
            </tbody>
        </table>
    </apex:form>    
    <script>
        var j$ = jQuery.noConflict();
        j$(document).ready(function() {
            $('#projectTable').DataTable(    
                {                    
                    "searching": false,
                    "lengthChange": false,
                    "pageLength": 25,
                    "info": false                  
                }         
            );
        } );
    </script>
    <!--
       // To sort the date column
       // [5] - is 5th column from 0 
                    "aoColumnDefs": [
                        { "sType": "date", "aTargets": [ 5 ] }
                     ]           
        //To seeting the width
        { "sWidth": "100px", "aTargets": [ 5 ] },
        { "sWidth": "100px", "aTargets": [ 4 ] },
        { "sWidth": "100px", "aTargets": [ 3 ] }
    -->
</apex:page>

No comments:

Post a Comment

Salesforce - Generate dynamic inner query to fetch parent and related child records

Use Case: In many scenarios, we need to clone the records with related child records. Issue / Limitation: We may simply use the "cl...