ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

jQuery DataTable in Salesforce Lightning Component

Home / Article & Blogs / Jquery / jQuery DataTable in Salesforce Lightning Component
By khushmeet Kaur inJquery, Lightning, Salesforce

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:-

https://code.jquery.com/jquery-3.5.1.js
https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js
https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js
https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css
https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css

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(',',
$Resource.jquery.dataTables.min,
$Resource.select.dataTables.min"
scripts="{!join(',',$Resource.jQuery35,
$Resource.dataTablesMinJS,
$Resource.dataTablesSelectMin
)}" 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%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Account Source</th>
<th>Annual Revenue</th>
<th>Industry</th>
</tr>
</thead>

<tbody>
<aura:iteration items="{!v.account}" var ="accountData" indexVar ="i">
<tr>
<td>{!i+1}</td>
<td>{!accountData.Name}</td>
<td>{!accountData.AccountSource}</td>
<td>{!accountData.AnnualRevenue}</td>
<td>{!accountData.Industry}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>


LIGHTNING CONTROLLER:-

({
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
action.setCallBack(this,function(response){
var state = response.getState();
if(state === 'SUCCESS'){
component.set("v.account",response.getReturnValue());
var j$ = jQuery.noConflict(); //To avoid conflict with any standard variables
setTimeout(function(){
var table = j$('#example').DataTable({
'columnsDefs' : [
{
'targets' : 0,
'checkboxes' : {
selectRow : true
}
}
],
'select' : {
'style' : 'multi'
},
'order' : [[1, 'asc']]
});
},200);
}
});
$A.enqueueAction(action);
},
})


APEX

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

 

Demo video

 

 

 

DatatableJqueryLightning componentSFDC
177
Like this post
3 Posts
khushmeet Kaur

Search Posts

Archives

Categories

Recent posts

Meet OmniStudio – Revolutionize Your Creative Work

Meet OmniStudio – Revolutionize Your Creative Work

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

  • Boost Recruiter’s Efficiency with Smart Candidate Recommendations
    Previous PostBoost Recruiter’s Efficiency with Smart Candidate Recommendations
  • Next PostTableau CRM: Add action buttons on Table without XMD
    Boost Recruiter’s Efficiency with Smart Candidate Recommendations

Related Posts

Meet OmniStudio – Revolutionize Your Creative Work
Salesforce

Meet OmniStudio – Revolutionize Your Creative Work

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT