Last active
February 2, 2016 11:32
-
-
Save Na0mir/b3b920736baaff2a8180 to your computer and use it in GitHub Desktop.
Display status % as a Progress bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List view, display, add and edit – Percent Complete Sample | |
// Muawiyah Shannak , @MuShannak | |
(function () { | |
// Create object that have the context information about the field that we want to change it's output render | |
var percentCompleteFiledContext = {}; | |
percentCompleteFiledContext.Templates = {}; | |
percentCompleteFiledContext.Templates.Fields = { | |
// Apply the new rendering for Status % field on List View and Display forms | |
"Status_x0020__x0025_": { | |
"View": percentCompleteViewFiledTemplate, | |
"DisplayForm": percentCompleteViewFiledTemplate | |
} | |
}; | |
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(percentCompleteFiledContext); | |
})(); | |
// This function provides the rendering logic for View and Display form | |
function percentCompleteViewFiledTemplate(ctx) { | |
var percentComplete = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; | |
var percentCompleteFloat = parseFloat(percentComplete); | |
if (percentCompleteFloat <= 30 ) | |
{ | |
return "<div style='background-color: #e5e5e5; width: 100px; display:inline-block;'><div style='width: " + percentComplete.replace(/\s+/g, '') + "; background-color: #d11141;'> </div></div> " + percentComplete; | |
} | |
else if (percentCompleteFloat > 30 && percentCompleteFloat <= 70) | |
{ | |
return "<div style='background-color: #e5e5e5; width: 100px; display:inline-block;'><div style='width: " + percentComplete.replace(/\s+/g, '') + "; background-color: #f37735;'> </div></div> " + percentComplete; | |
} | |
else if (percentCompleteFloat > 70 && percentCompleteFloat <= 99) | |
{ | |
return "<div style='background-color: #e5e5e5; width: 100px; display:inline-block;'><div style='width: " + percentComplete.replace(/\s+/g, '') + "; background-color: #ffc425;'> </div></div> " + percentComplete; | |
} | |
else | |
{ | |
return "<div style='background-color: #e5e5e5; width: 100px; display:inline-block;'><div style='width: " + percentComplete.replace(/\s+/g, '') + "; background-color: #00b159;'> </div></div> " + percentComplete; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment