jQuery DataTable in Salesforce Lightning Component

jQuery DataTable in Salesforce Lightning Component

jQuery Datatable is a powerful plugin that will allow creating a table with advanced features and interactive control. It provides searching, sorting, pagination, multiple selections, and many other features. This post will fetch the sample Data from salesforce and display using the jQuery Datatable.

In order to use the jQuery Datatable , the jQuery library files must be uploaded as a static resource and later the static resources to be loaded in the lightning component

Step 1

Download the files from the below URL:-

For the download of the files, click on the link and press CTRL+S from the keyboard or right-click on the page and save the file.

Step 2:-

Upload the downloaded files in the static resource, once the files are uploaded in the static resource it can be referred to in the lightning component.

  • To upload the files Setup->Static Resource->New
  • In the Name, field enters the name for the resource that can be used in the lightning component.
  • Choose the file from the local storage.
  • In Cache-Control drop-down list, choose Public in order to make accessible the resource for the lightning component.
  • Click on the Save button.

Step 3:-
Create a new lightning component that will be used to display the data table.
Lightning Controller:-

<aura:component controller="demoController">
<ltng:require styles ="{!join(',',
)}" afterScriptsLoaded="{!c.scriptsLoaded}"/>

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="account" type="List"/>

<table id="example" class="display" cellspacing="0" width="100%">
<th>Account Source</th>
<th>Annual Revenue</th>

<aura:iteration items="{!v.account}" var ="accountData" indexVar ="i">


scriptsLoaded : function(component,event,helper){
console.log('scripts loaded');

doInit : function(component,event,helper){
var action= component.get("v.fetchAccountList"); //Call apex class to fetch the data from database
var state = response.getState();
if(state === 'SUCCESS'){
var j$ = jQuery.noConflict(); //To avoid conflict with any standard variables
var table = j$('#example').DataTable({
'columnsDefs' : [
'targets' : 0,
'checkboxes' : {
selectRow : true
'select' : {
'style' : 'multi'
'order' : [[1, 'asc']]


public with sharing class demoController {
public static list <Account> fetchAccountList()
Return [SELECT Name,AccountSource,AnnualRevenue,Industry FROM Account LIMIT 500];              

Demo video

Recent Posts

low Code vs pro code automation with flow and code
Low-Code vs Pro-Code | Automation with Flow and Code
devops introduction seamless development and operations
DevOps Introduction: Seamless Development and Operations
salesforce for small businesses success
Salesforce for Small Businesses Success
salesforce communities building stronger customer relationships
Salesforce Communities: Building Stronger Customer Relationships
salesforce app cloud what exactly is it and its advantages
Salesforce App Cloud: What Exactly is it & its Advantages?
Scroll to Top