How To Use jQuery DataTable Plugin In Salesforce Lightning Component
How To Use jQuery DataTable Plugin In Salesforce Lightning Component
jQuery DataTables is a very powerful plugin for creating table with advanced interaction controls. It provides searching, sorting, pagination and many more cool features without any configuration. In this post we are going to learn how we can use this jQuery datatable in salesforce lightning components.
So in this sample post, we will fetch the opportunity object records from server and after that display those records using jQuery data table.
Step 1 : Download & Upload jQuery library and jQuery data table plugin, in static resource.
In order to use data table jQuery plugin, you must include the jQuery, javaScript and CSS file on your Lightning Component via static resources.
Download Data Table jQuery Plugin
Go to below link for download data table plugin. [version 1.10.16 Recommended]
Step 2 : Upload Data Table zip file + jQuery js file as a static resources in your Salesforce org.
Static resource is a file or collection of files that is stored on Salesforce. Once your Data Table zip file and jQuery2.2.4 JS file is added as a static resource, it can be referenced by any of your lightning component.
After successfully download both files (DataTables-1.10.16.zip + jQuery js file) now, we can upload these as a static resources.
For upload zip file, from Setup >> Develop >> Static Resources >> New.
In the Name field, enter the name which is use in lightning component.
Click Choose File or Browse, and select dataTable zip file which we downloaded before.
In the Cache Control drop-down list, select Public.
Click on the Save button.
Follow same steps to upload both files.
Data Table Zip file upload…
jQuery 2.2.4 JS file upload
Step 3 : Use jQuery Data Table on salesforce lightning component.
Step 4 : Create Apex Controller
From developer console >> file >> new >> Apex Class
jQueryDataTableCtrl.apxc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
Source : Sfdcmonkey.com
API Version: 42
Date : 3/13/2018
*/
publicwithsharingclassjQueryDataTableCtrl{
@AuraEnabled
publicstaticlistfetchOpportunity(){
Return[SELECT Name,Type,StageName,Amount,CloseDate FROM Opportunity LIMIT500];
}
}
Step 5 : Create Lightning Component
From developer console >> file >> new >> Lightning Component
No comments:
Post a Comment