Using Jquery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages PDF
Using Jquery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages PDF
SourceCode.zip
Introduction
In this article, we will learn how to pass SharePoint List Data to a jQuery DataTable using REST API
and display SharePoint list data on SitePages using DataTable.
DataTables is a plug-in for the jQuery Javascript library. It is a highly exible tool, based on the
foundations of progressive enhancement, and will add advanced interaction controls to any
HTML table.
[O cial Site] : https://datatables.net/ - Please refer to the o cial site for documentation and the
getting started guide
Before starting with this post, we must have some basic knowledge of the following.
HTML Tables
Rest API in SharePoint
JavaScript
Implementation
Step 1
Create a Sharepoint List with data, this is the list from which we will retrieve the data and pass the
data to jQuery DataTable. Skip this step if you already have the Data Source List on your
SharePoint Site.
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 1/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
I have created a list of sample data for our project, Sample Data Source: jQuery DataTable O cial
Site, You can also use import
LEARN: Reactspreadsheet SharePoint App to import bulk data from excel
Virtual Conference
spreadsheet
C# Corner vincenttacda
Post Ask
Question
Step 2
Now we will create the script le and the html Site page for displaying the list data.
We need to follow CDN scripts, that are required to be used in our functionality
jquery.min.js
jquery.dataTables.min.js
jquery.dataTables.min.css
dataTables.jqueryui.min.css
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 2/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
jquery.min.js should be loaded before jquery.dataTables.min.js as shown in the below code block,
Step 3
Now, we will get Data from the SharePoint list. For this, write a function to get the data, using
REST API.
Create the GetData.js le in a text editor (I use notepad ++)
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 3/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
Note
Step 4
Now we will bind the data obtained from the API Call with the jQuery DataTable [HTML View].
mySuccessHandler function binds the data to the DataTable.
myErrHandler function
01. $(document).ready(function() {
02. loadItems();
03. });
04.
05.
06. function loadItems() {
07. var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
08. var oDataUrl = siteUrl + "/_api/web/lists/getbytitle('EmployeeInfo')/ite
$select=Title,Position,Office,Age,Joining_x0020_date";
09. $.ajax({
10. url: oDataUrl,
11. type: "GET",
12. dataType: "json",
13. headers: {
14. "accept": "application/json;odata=verbose"
15. },
16. success: mySuccHandler,
17. error: myErrHandler
18. });
19. }
20.
21. function mySuccHandler(data) {
22. try {
23.
24. $('#table_id').DataTable({
25.
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 5/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
Step 5
Copy both the les [html and JavaScript] to SharePoint SiteAssets Library.
Create a Webpart Page (Named DataTable) and store it in the pages or the site pages library.
Add a content editor to DataTable Page. Now, give HTML le reference to the content editor into
Content Editor.
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 6/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
C# Corner vincenttacda
Post Ask
Question
Real-Time Search, Paging, Sorting, View Functionality [In-built DataTable functionality - NO
CODE]
I hope this article was helpful in getting started with the jQuery DataTable plugin. Please share
your valuable suggestions and feedback.
Brought to you by: Embed analytics and dashboards right inside your app with a JS SDK. Free Demo.
OUR BOOKS
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 7/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
C# Corner vincenttacda
Post Ask
Question
Guest User
67k
5 11
Type your comment here and press Enter Key (Minimum 10 characters)
Follow Comments
It worked great for me. I can able to view the data. But It shows only 100 rows and link is not
available. Kindly suggest
Karthick N Jan 29, 2020
1933 15 0 0 0 Reply
I only have the html loaded (column headers). Do I need to upload datatables.min and so on to site
assets. I have the get data js le linked correctly.
Sarmad Yousif Oct 08, 2019
1854 94 676 0 1 Reply
How to add these buttons : copy, excel, pdf. I am getting syntax error if i follow the syntax which is
given on datatables.net website, please help
Ullas Anand Apr 25, 2019
1944 4 0 0 0 Reply
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 8/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
Can you please suggest how to format the date eld for the same code if it is returning the deta eld
data as 2015-09-30T18:30:00Z. I want this in dd-mm-yyyy format
Anish Gupta Mar 25, 2019
LEARN: React Virtual Conference
1912 36 0 0 0 Reply
C# Corner vincenttacda
Awesome job! Is there some option for select multiple lines enabling check boxes as rst column?
Eduardo Araujo Post Ask Dec 17, 2018
1936 12 0 0 0 Reply
Question
Thanks Akshat. What would you do if items more than 5000? Regular user (not admin) will get
standart threshold retrieving 5000 items...
Siskoglaz Siskoglaz Aug 08, 2018
1942 6 0 0 0 Reply
Great solution! What would be the syntax for the use of "Use $top=5000 if items more than 100"?
Where would I place that and how would it look?
Bryan Waldrop Jun 13, 2018
1943 5 0 0 2 Reply
Thanks! By default SharePoint REST API fetches only top 100 items from the list.So to get all
the items from the list where items are more than 100 use syntax $top=5000 - fetches top
5000 items from the list (i.e. As SharePoint List View Threshold Limit = 5000 so our query
will return all list items) [Syntax : var oDataUrl = siteUrl +
"/_api/web/lists/getbytitle('EmployeeInfo')/items?
$select=Title,Position,O ce,Age,Joining_x0020_date&$top=5000"; //append $top=5000 to
existing API Data URL ]
Guest User Jun 17, 2018
Tech Writer 127 67k 1
Excellent thank you! And what form would an additional lter take that limited the table
data loaded to the user login, assuming there was a matching data in one of the table
columns?
Bryan Waldrop Jun 25, 2018
1943 5 0 0
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 9/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
C# Corner vincenttacda
Post Ask
Question
FEATURED ARTICLES
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 10/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
C# Corner vincenttacda
Post Ask
Question
TRENDING UP
03 Create User Login And Registration Using Web API And React Hooks
05 Installing VS Code and Dot Net Core SDK on Latest Ubuntu 20.04(linux) 2020
07 How to Install Ubuntu 20.04 LTS on VirtualBox in Windows 10 Operating System (2020)
C# Corner vincenttacda
Post Ask
Question
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 12/13
8/20/2020 Using jQuery DataTable To Display SharePoint 2013 List Data On SharePoint Site Pages
C# Corner vincenttacda
Post Ask
Question
About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners
https://www.c-sharpcorner.com/article/using-jquery-datatable-to-display-sharepoint-list-data-on-share/ 13/13