0

Is there a possibility to color the File Size column in SharePoint 2013 with CSR? I want to color the column based on the actual file size.

e.g.
if the file is smaller than 10 MB then green,
if its between 10 and 30 mb yellow and when it's bigger than 30 mb red.

Maybe something like this? this article

Regards Michael

1
  • Add file size column to your view
  • The Internal name of file size is File_x0020_Size
  • Try to use this code at your JSLink with your condition based on File Size
    Type.registerNamespace('CustomFormat');

    CustomFormat.riskColor = function () {

    var riskFieldsContext = {};
    riskFieldsContext.Templates = {};
    riskFieldsContext.Templates.Fields = {
        "File_x0020_Size": { "View": CustomFormat.exposureColourTemplate }        
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(riskFieldsContext);


 }

 // This function provides the rendering logic for list view
CustomFormat.exposureColourTemplate = function(ctx) {
  var fieldValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];

  if (parseFloat(fieldValue) < 10000) {
      return "<span style='background-color : green'>&nbsp;&nbsp;&nbsp;&nbsp;</span> High (" + fieldValue + ")";
  }
  else if (parseFloat(fieldValue) >= 10000 && parseFloat(fieldValue) =<  30000) {
      return "<span style='background-color : yellow'>&nbsp;&nbsp;&nbsp;&nbsp;</span> Medium (" + fieldValue + ")";
  }
  else {
      return "<span style='background-color : red'>&nbsp;&nbsp;&nbsp;&nbsp;</span> Low (" + fieldValue + ")";
  }
}

//CSR-override for MDS disabled site 
CustomFormat.riskColor();

if (typeof _spPageContextInfo != "undefined" && _spPageContextInfo != null) {         
  // CSR-override for MDS enabled site
  RegisterModuleInit(_spPageContextInfo.siteServerRelativeUrl + "/SiteCollectionDocuments/riskColor.js", CustomFormat.riskColor); 
}

For more details check client-side-rendering-2013

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.