In SharePoint 2013 we can use the new JS Link property in different web parts to manipulate the output (or input) in these fields. I have written some articles in my blog about how to do this. All these articles have in common that the JavaScript file only manipulates one column. But with the JS Link extension it is very simple to implement the manipulation to more than one field. Because the Templates.Fields member is able to hold the reference to more than one field, the variable that is used to register the view template needs only a small extension as shown in the following script snipped.

(function () {
  var statusFieldCtx = {};

  statusFieldCtx.Templates = {};
  statusFieldCtx.Templates.Fields = {
    "DueDate":   {
                   "View": StatusFieldViewTemplate
                 },
    "Remaining": {
                   "View": RemainingFieldViewTemplate
                 },
    "Today":     {
                   "View": TitleFieldViewTemplate
                 }
  };

  SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtx);
})();

To the Templates.Fields member just simply add a list of fields with their view template function, separated by a comma.

All you need additionally in the script are the functions that are referenced in the Templates.Fields assignment (in the example “StatusFieldViewTemplate, etc.”).

Advertisements