{"id":11459,"date":"2016-05-24T06:06:00","date_gmt":"2016-05-24T06:06:00","guid":{"rendered":"https:\/\/viewmyprojects.com\/winwirewp\/?p=11459"},"modified":"2023-11-30T09:52:27","modified_gmt":"2023-11-30T09:52:27","slug":"sharepoint-2013-client-side-rendering","status":"publish","type":"post","link":"https:\/\/viewmyprojects.com\/winwirewp\/blog\/sharepoint-2013-client-side-rendering\/","title":{"rendered":"SharePoint 2013 Client-side rendering"},"content":{"rendered":"\n<p><strong>Client-side rendering (JS Link)<\/strong><\/p>\n\n\n\n<p>You can use it to style complete List Views, Fields, Search Results and more. This makes it a lot simpler and more intuitive, especially for web developers who haven\u2019t used SharePoint before.<br>JSLink files have the ability to quickly and easily change how the list views and forms are rendered.<br>More specifically how the fields in that list should be displayed.<\/p>\n\n\n\n<p><strong>Overview<\/strong><\/p>\n\n\n\n<p>Client-side rendering is a new concept in SharePoint 2013. It provides you with a mechanism that allows you to use your own output render for a set of controls that are hosted on a SharePoint page (list views, display, add and Edit forms).<\/p>\n\n\n\n<p>Client Site Rendering is simply when the data is transformed using the client rather than the server. This means using client-side technologies, such as HTML and JavaScript. It allows us to style SharePoint elements using JavaScript, rather than having to write XSLT.<\/p>\n\n\n\n<p><strong>How to deploy the JSLink templates?<\/strong><\/p>\n\n\n\n<p>Below are the options to deploy JS Link.<br>1. Set the JS Link property on a List View Web Part<br>2. Set the SPField.JSLink property in the Field XML definition<br>3. Set the SPField.JSLink property using the Server-Side Object Model<br>4. Set the SPField.JSLink property using PowerShell<\/p>\n\n\n\n<p><strong>Example on Client-side rendering (JS Link)<br><\/strong><br>Below sample shows deploying JSLink using list view web part.<br>Requirement: Update SharePoint list specific item by clicking specific row button as shown in below screenshot. (Rendering SharePoint list field as update button using Client-side rendering).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"276\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni-a.webp\" alt=\"\" class=\"wp-image-18803\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni-a.webp 626w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni-a-300x132.webp 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p><strong>\u2022 Create a custom list as shown in below screenshot<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"211\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni-b.webp\" alt=\"\" class=\"wp-image-18802\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni-b.webp 626w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni-b-300x101.webp 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p><strong>\u2022 Edit a web part to call the JSlink file.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"243\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Trivenic.webp\" alt=\"\" class=\"wp-image-18801\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Trivenic.webp 626w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Trivenic-300x116.webp 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p><strong>\u2022 Below screenshot shows rendered hyperlink field as a button.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"351\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni3.webp\" alt=\"\" class=\"wp-image-18811\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni3.webp 625w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni3-300x168.webp 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p><strong>\u2022 Add the JS file path in the JS Link section shown below<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"297\" height=\"529\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni-6.webp\" alt=\"\" class=\"wp-image-18808\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni-6.webp 297w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni-6-168x300.webp 168w\" sizes=\"auto, (max-width: 297px) 100vw, 297px\" \/><\/figure>\n\n\n\n<p><br><\/p>\n\n\n\n<p><strong>Note:<\/strong><\/p>\n\n\n\n<p><strong>~site<\/strong>\u2013 if the .js file is located on the site where your list view Web Part exist.<\/p>\n\n\n\n<p><strong>~sitecollection<\/strong>\u2013 if the .js file is located in the site collection level.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Below script shows rendering \u201cUpdateItem\u201d hyperlink field as a&nbsp;button in every row&nbsp;and on click on a&nbsp;button, open a specific row to edit an item.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"230\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni7-1.webp\" alt=\"\" class=\"wp-image-18807\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni7-1.webp 626w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni7-1-300x110.webp 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p><strong>.JS file<\/strong><\/p>\n\n\n\n<p>(function () {<\/p>\n\n\n\n<p>\/\/ Intialize the variables for overrides objects<\/p>\n\n\n\n<p>var overrideCtx = {};<\/p>\n\n\n\n<p>overrideCtx.Templates = {};<\/p>\n\n\n\n<p>overrideCtx.Templates.Fields = {<\/p>\n\n\n\n<p>\u2018PercentComplete\u2019: { \u2018View\u2019 : \u2018&lt;div style=\u201dbackground: #F3F3F3; display:block; height: 20px; width: 100px;\u201d&gt;&lt;div style=\u201dbackground: #0072C6; height: 100%; width: &lt;#=ctx.CurrentItem.PercentComplete.replace(\u201d %\u201d, \u201c\u201d)#&gt;%;\u201d&gt;&lt;\/div&gt;&lt;\/div&gt;\u2019 },<\/p>\n\n\n\n<p>\u2018UpdateItemJS\u2019: { \u2018View\u2019 : getSelectedItem}<\/p>\n\n\n\n<p>};<\/p>\n\n\n\n<p>SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);<\/p>\n\n\n\n<p>})();<\/p>\n\n\n\n<p>function getSelectedItem(ctx){<\/p>\n\n\n\n<p>var ret = \u201c&lt;button onclick=\\\u201dOpenDialog(\u2018Servername:Port\/Lists\/JSLinkTest\/EditForm.aspx?ID=\u201d+ctx.CurrentItem.ID+\u201d\u2018);\\\u201d&gt;Update Item&lt;\/button&gt;\u201d ;<\/p>\n\n\n\n<p>return ret;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>function OpenDialog(URL) {<\/p>\n\n\n\n<p>var options = SP.UI.$create_DialogOptions();<\/p>\n\n\n\n<p>options.url = URL;<\/p>\n\n\n\n<p>options.width = 600;<\/p>\n\n\n\n<p>options.height = 400;<\/p>\n\n\n\n<p>options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);<\/p>\n\n\n\n<p>SP.UI.ModalDialog.showModalDialog(options);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>function CloseCallback(result, target) {<\/p>\n\n\n\n<p>location.reload(true);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u2022 Below screenshot shows rendered hyperlink field as the button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"627\" height=\"319\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni8.webp\" alt=\"\" class=\"wp-image-18806\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni8.webp 627w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni8-300x153.webp 300w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/figure>\n\n\n\n<p><strong>\u2022 Click on the \u201cUpdate Item\u201d button to edit a specific row.<br><\/strong><br><a href=\"https:\/\/www.winwire.net\/wp-content\/uploads\/2016\/05\/triveni9.png\" target=\"_blank\" rel=\"noopener\"><\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"213\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni9.webp\" alt=\"\" class=\"wp-image-18805\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni9.webp 626w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni9-300x102.webp 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p><strong>\u2022 On click of Update Item button, below model pop up will open to update an item.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"460\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni11.webp\" alt=\"\" class=\"wp-image-18804\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni11.webp 624w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/triveni11-300x221.webp 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p><strong>\u2022Below screenshot shows updated item saved in an \u201cEmpProfInfo\u201d list.<br><\/strong><br><a href=\"https:\/\/www.winwire.net\/wp-content\/uploads\/2016\/05\/Triveni4.jpg\" target=\"_blank\" rel=\"noopener\"><\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"276\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni4.webp\" alt=\"\" class=\"wp-image-18810\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni4.webp 625w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni4-300x132.webp 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p><strong>More examples<\/strong><\/p>\n\n\n\n<p>Requirement: Rendering KPI icons based on status and showing theprogress of atask.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"251\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni5-1.webp\" alt=\"\" class=\"wp-image-18809\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni5-1.webp 626w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Triveni5-1-300x120.webp 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p>Code in js file:<br>(function () {<br>\/\/ Intialize the variables for overrides objects<br>var overrideCtx = {};<br>overrideCtx.Templates = {};<br>overrideCtx.Templates.Fields = {<br>\u2018Status\u2019: { \u2018View\u2019 : ChangeStatusIcon},<br>\u2018PercentComplete\u2019: { \u2018View\u2019 : \u2018&lt;div style=\u201dbackground: #F3F3F3; display:block; height: 20px; width: 100px;\u201d&gt;&lt;div style=\u201dbackground: #0072C6; height: 100%; width: &lt;#=ctx.CurrentItem.PercentComplete#&gt;%;\u201d&gt;&lt;\/div&gt;&lt;\/div&gt;\u2019 }<br>};<br>SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);<br>})();<\/p>\n\n\n\n<p>function ChangeStatusIcon(ctx)<br>{<br>switch (ctx.CurrentItem.Status) {<br>case \u2018Not Started\u2019:<br>var ret = \u201c&lt;img src=\u2019Servername:port\/Converge\/WinWireDocuments\/Images\/NotStarted.png\u2019&gt; Not Started&lt;\/img&gt;\u201d ;<br>return ret;<br>break;<br>case \u2018In-Progress\u2019:<br>var ret = \u201c&lt;img src=\u2019Servername:port\/Converge\/WinWireDocuments\/Images\/InProgress.png\u2019&gt; In-Progress&lt;\/img&gt;\u201d ;<br>return ret;<br>break;<br>case \u2018Completed\u2019:<br>var ret = \u201c&lt;img src=\u2019 Servername:port\/Converge\/WinWireDocuments\/Images\/Completed.png\u2019 &gt; Completed&lt;\/img&gt;\u201d ;<br>return ret;<br>break;<br>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Client-side rendering (JS Link) You can use it to style complete List Views, Fields, Search Results and more. This makes it a lot simpler and more intuitive, especially for web developers who haven\u2019t used SharePoint before.JSLink files have the ability to quickly and easily change how the list views and forms are rendered.More specifically how&hellip; <a class=\"more-link\" href=\"https:\/\/viewmyprojects.com\/winwirewp\/blog\/sharepoint-2013-client-side-rendering\/\">Continue reading <span class=\"screen-reader-text\">SharePoint 2013 Client-side rendering<\/span><\/a><\/p>\n","protected":false},"author":44,"featured_media":16746,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-11459","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","entry"],"acf":[],"featured_image_src":"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013.webp","author_info":{"display_name":"Triveni","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/triveni\/"},"views":4314,"uagb_featured_image_src":{"full":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013.webp",800,440,false],"thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013-150x150.webp",150,150,true],"medium":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013-300x165.webp",300,165,true],"medium_large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013-768x422.webp",750,412,true],"large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013.webp",750,413,false],"1536x1536":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013.webp",800,440,false],"2048x2048":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013.webp",800,440,false],"post-thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/SharePoint-2013.webp",800,440,false]},"uagb_author_info":{"display_name":"Triveni","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/triveni\/"},"uagb_comment_info":0,"uagb_excerpt":"Client-side rendering (JS Link) You can use it to style complete List Views, Fields, Search Results and more. This makes it a lot simpler and more intuitive, especially for web developers who haven\u2019t used SharePoint before.JSLink files have the ability to quickly and easily change how the list views and forms are rendered.More specifically how&hellip;&hellip;","_links":{"self":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/11459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/comments?post=11459"}],"version-history":[{"count":2,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/11459\/revisions"}],"predecessor-version":[{"id":18855,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/11459\/revisions\/18855"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media\/16746"}],"wp:attachment":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media?parent=11459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/categories?post=11459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/tags?post=11459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}