Introduction
JSLink is JavaScript link [ CSR - Client-side rendering]. This feature was introduced in SharePoint 2013 for customizing SharePoint list forms Newfrom, displayform, editform.
Using this feature, you can change the overall look and feel of the SharePoint list. It works well to customize the SharePoint components using OOTB (Out Of the Box).
Let’s get started to implement jQuery datatable.
Open SharePoint site
Create a SharePoint custom list with some data.

Open SharePoint Designer -> Navigate to Site Assets -> Create a file customize.js.

Next, upload all the CSS and JavaScript plugins for building a datatable.
Download here - Datatable
Upload all the CSS and JavaScript files into Site Assets library.

Open the customize.js and start building code.
Add CSS and JavaScript
Inside a JavaScript file, you can call the CSS like this.
- /Declare my custom css for design HTML
- var cssId = 'myCss';
- if (!document.getElementById(cssId)) {
- var head = document.getElementsByTagName('head')[0];
- var link = document.createElement('link');
- link.id = cssId;
- link.rel = 'stylesheet';
- link.type = 'text/css';
- link.href = 'https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/css/jquery-ui.css';
- link.media = 'all';
- head.appendChild(link);
- }
- var cssId = 'myCss1';
- if (!document.getElementById(cssId)) {
- var head = document.getElementsByTagName('head')[0];
- var link = document.createElement('link');
- link.id = cssId;
- link.rel = 'stylesheet';
- link.type = 'text/css';
- link.href = 'https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/css/dataTables.jqueryui.min.css';
- link.media = 'all';
- head.appendChild(link);
- }
Create a function for overriding the item template. Inside the function, declare necessary jQuery Snippets.
- (window.jQuery || document.write('<script src="https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/js/jquery-1.12.4.js"><\/script>'));
- (window.jQuery || document.write('<script src="https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/js/jquery.dataTables.min.js"><\/script>'));
- (window.jQuery || document.write('<script src="https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/js/dataTables.jqueryui.min.js"><\/script>'));
HTML Code
- <table id="example" class="display" cellspacing="0" width="100%">
- <thead>
- <tr>
- <th>Name</th>
- <th>Position</th>
- <th>Office</th>
- <th>Age</th>
- <th>Start date</th>
- <th>Salary</th>
- </tr>
- </thead>
- <tfoot>
- <tr>
- <th>Name</th>
- <th>Position</th>
- <th>Office</th>
- <th>Age</th>
- <th>Start date</th>
- <th>Salary</th>
- </tr>
- </tfoot>
- <tbody>
- <tr>
- <td>Tiger Nixon</td>
- <td>System Architect</td>
- <td>Edinburgh</td>
- <td>61</td>
- <td>2011/04/25</td>
- <td>$320,800</td>
- </tr>
- <tr>
- <td>Garrett Winters</td>
- <td>Accountant</td>
- <td>Tokyo</td>
- <td>63</td>
- <td>2011/07/25</td>
- <td>$170,750</td>
- </tr>
- </tbody>
- </table>
Now, override the default list template.
- (function () {
- (window.jQuery || document.write('<script src="https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/js/jquery-1.12.4.js"><\/script>'));
- (window.jQuery || document.write('<script src="https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/js/jquery.dataTables.min.js"><\/script>'));
- (window.jQuery || document.write('<script src="https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/datatable/js/dataTables.jqueryui.min.js"><\/script>'));
- var overrideCtx = {}; // Create a variable for override context
- overrideCtx.Templates = {} // Get the templates of the list
- //Declare the template header with HTML Tags
- overrideCtx.Templates.Header = " <table id='example' class='display' cellspacing='0' width='100%'><thead><tr><th>Product</th><th>Description</th><th>Quantity</th><th>Make/Model</th><th>Price</th></tr></thead><tfoot><tr><th>Product</th><th>Description</th><th>Quantity</th><th>Make/Model</th><th>Price</th></tr></tfoot><tbody>";
- // Get the Item data from context
- overrideCtx.Templates.Item = dataTemplate;
- //Declare the template footer with HTML tags
- overrideCtx.Templates.Footer = "</tbody></table>";
- // Onpostrender event fires after the DOM is loaded
- overrideCtx.OnPostRender = dataTableOnPostRender;
- //Register the template overrides
- SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
- })();










Ajay SharmaPosted Jun 18, 2018, 1:09 AM
I have found an issue with group by else it is working.
Ajay SharmaPosted Jun 15, 2018, 1:40 AM
Hi Vinod, It is not working for task list. Please suggest the solution.
Shankar NSPosted Apr 9, 2018, 12:11 PM
Dear Vinod, excellent article. It works perfectly on SP on prem. I tried the same on SP online and it does not work. Any idea what could be the issue?
venkat KotaiahPosted Dec 11, 2017, 11:39 PM
Hi Vinod have a nice day..i have tried same process but for me its not working ...i have forward my code to your mail kindly do some needful .....
venkat KotaiahPosted Dec 8, 2017, 12:58 AM
Hi vinodh have a nice i tried same process as above but i am getting error like Failed to load resource: the server responded with a status of 404 () can you please help out me on this
venkat KotaiahPosted Dec 7, 2017, 7:40 AM
Hi Vinodh Were we can write html code in list view webpart we linking only js file i am missing html file ..can you help out me were we link html code to our code