Skip to content

Instantly share code, notes, and snippets.

@markgarg
Created February 3, 2015 11:18
Show Gist options
  • Save markgarg/905c1775608c83cc64de to your computer and use it in GitHub Desktop.
Save markgarg/905c1775608c83cc64de to your computer and use it in GitHub Desktop.
public with sharing class BeerPaginatorJSRemoting {
public BeerPaginatorJSRemoting() {
// Do nothing
}
@RemoteAction
public static List<Beer__c> getBeerList(){
List<Beer__c> beerList = [SELECT Id, Name, Tags__c, Alcohol__c, Brewery__r.Name FROM Beer__c LIMIT 1000];
return beerList;
}
}
<apex:page showHeader="true" sidebar="true" docType="html-5.0" controller="BeerPaginatorJSRemoting">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css"/>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.js"></script>
<apex:sectionHeader title="Beer sorting paginator" />
<table id="beerTable">
<thead>
<th>Name</th>
<th>Alcohol %</th>
<th>Tags</th>
<th>Brewery</th>
</thead>
<tbody></tbody>
</table>
<script type='text/javascript'>
$(document).ready(function(){
$('#beerTable').dataTable({
"paging": true,
"jQueryUI": true,
"ajax": function(data, callback, settings){
BeerPaginatorJSRemoting.getBeerList(function(result, event){
if(event.type == 'exception')
alert('Exception');
else
callback({'data':result})
});
},
"columns": [
{
"data": "Name"
},
{
"data": "Alcohol__c"
},
{
"data": "Tags__c"
},
{
"data": "Brewery__r.Name"
}
]
});
})
</script>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment