SharePoint Pals
 | Sign In
How to use Client Side Rendering (JSLink) in a SharePoint Hosted APP
by Krishna KV 18 Sep 2016
Team Leader, Aspire Systems
Today  :   3     Total  :    1288

JSLink is a new feature that is introduced in SharePoint 2013. It is a combination of Html, javascript and css to customize the rendering of SharePoint List views and forms. It can be called as Client Side Rendering (CSR rather than writing a XSLT)

· The rendering happens in the client side, so the pages can load faster with CSR.

· Compare to XSLT, JavaScript will be easier to development and debugged.

· We can customize specific fields, header, body and footer.

Create a SharePoint hosted app.




Adding columns in the list.


Adding custom view to the list can be provide any name and select the columns to view.


Schema.xml under view 2 include the custom script.

 <View BaseViewID="2" Name="2757a7d6-f368-47e7-bbda-5bcfdb318b60" DisplayName="NewView" Type="HTML" WebPartZoneID="Main" SetupPath="pages\viewpage.aspx" Url="NewView.aspx">
     <FieldRef Name="LinkTitle" />
     <FieldRef Name="StartDate" />
     <FieldRef Name="_EndDate" />
     <FieldRef Name="PercentComplete" />
     <FieldRef Name="Project" />
     <FieldRef Name="Edit" />
 <Query />
 <Toolbar Type="Standard" />
 <XslLink Default="TRUE">main.xsl</XslLink>
 <JSLink Default="TRUE">~site/Scripts/ListRender.js</JSLink>

Add the ListRender.js under the script folder

 (function () {
     var overrideCtx = {};
     overrideCtx.Templates = {};
     overrideCtx.Templates.Header = "<h2><#=ctx.ListTitle#></h2>" +
         "<table class='table table-striped'><tr><th>Title</th><th>Start Date</th><th>End Date</th><th>Project</th><th>Progress </th></tr>";
     // This template is assigned to the CustomItem function.
     overrideCtx.Templates.Item = customItem;
     overrideCtx.Templates.Footer = "</table>";
     overrideCtx.BaseViewID = 2;
     overrideCtx.ListTemplateType = 100;
     overrideCtx.OnPreRender = loadCss;
 function customItem(ctx) {
     var ret = "<tr><td>" + ctx.CurrentItem.Title + "</td>";
     ret += "<td>" + ctx.CurrentItem.StartDate + "</td>";
     ret += "<td>" + ctx.CurrentItem._EndDate + "</td>";
     ret += "<td>" + ctx.CurrentItem.Project + "</td>";
     ret += "<td>" + getProgress(parseInt(ctx.CurrentItem["PercentComplete."])) + "</td></tr>"
     return ret;
 function getProgress() {
     return  '<div class="progress">' +
             '<div class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width:' + value + '%">' + value + '%' +
 function loadCSS(ctx) {
     document.write('<link rel="Stylesheet" type="text/css" href="../../Content/bootstrap.css"/>');



blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter October 23, 22:21
How to Add/Remove User Custom Actions (in Site Actions Menu) Programmatically using CSOM PNP in SharePoint -

Twitter October 21, 21:34
How to Add a JS Link Reference to the Display Form or Any other ASPX Programmatically using CSOM PNP in SharePoint -

Twitter October 20, 13:01
How to Add a JS Link Reference to the NewForm and EditForm Programmatically using CSOM PNP in SharePoint Office 365-

Twitter October 12, 12:15
How to Deploy Provider Hosted Apps (Add-Ins) by App Stapling in SharePoint Office 365 -

Twitter October 11, 13:39
How to Deploy Provider HostedApp programmatically using CSOM in SharePoint Office 365 Activating Developer Feature -

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation