Archive for December, 2014

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.

Leave a comment