Customizing SharePoint 2013 OOTB List view using JSLink

JSLink in SharePoint 2013 is a nice and only way to keep all the power of OOTB list view Web Part and add your own customizations. Here’s a simple example of highlighting an item row based on a column value.


(function () {
 var context = {};
 context.Templates = {};

 context.OnPostRender = [HighlightRowOverride];
 SPClientTemplates.TemplateManager.RegisterTemplateOverrides(context);

})();

function HighlightRowOverride(context) {

 for (var i = 0; i < context.ListData.Row.length; i++) {
 var listItem = context.ListData.Row[i];

 if (listItem["_Status"] == "Change requested") {
 var iid = GenerateIIDForListItem(context, listItem);
 var row = document.getElementById(iid);

 if (row.length != 0) {
 $(row).addClass("row-highlight");
 }
 }

 }

}

Below is an example of an another customized list view Web Part, the grey table has been added through JSLink.
jslink

Pritam Baldota has explained in his MSDN Magazine article different ways of deploying and adding JSLink scripts the list view Web Parts.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: