As you probably have already seen, the name of the closed tasks (the ones having 100% completeness) is displayed using a strikethrough text in the All Tasks view of a task list in SharePoint. For example, from the tasks below, only Task 2 is 100 % complete.
Our users would like to have the same functionality in the Risks list on Project Server project sites, but out of the box, the title of the closed risks (ones having Status = "(3) Closed") is displayed without strikethrough, using the same formatting as any other risks:
Note: I assume you are familiar with client-side rendering. If not, and would like to understand how our solution works, I suggest you to read about it first, for example in the excellent post of Chris O’Brien.
After a short research, I found that this functionality of the Task lists is implemented in 15\TEMPLATE\LAYOUTS\hierarchytaskslist.debug.js. See the CompletedTitleTemplate template in that .js file.
Based on that template it was easy to implement the required functionality:
- (function () {
- if (typeof window.CompletedRiskTitleTemplate == "object") {
- return;
- }
- window.CompletedRiskTitleTemplate = {
- RenderTitleField: function (inCtx, field, listItem, listSchema) {
- var titleHtml = ComputedFieldWorker[field.Name](inCtx, field, listItem, listSchema);
- var result = (listItem["Status"] == "(3) Closed") ?
- '<span style="text-decoration: line-through">' + titleHtml + '</span>' :
- titleHtml;
- return result;
- }
- };
- function _registerCompletedRiskTitleTemplate() {
- var TitleFieldContext = {
- Templates: {
- Fields: {
- 'LinkTitle': {
- 'View': window.CompletedRiskTitleTemplate.RenderTitleField
- }
- },
- ListTemplateType: 1101
- }
- };
- SPClientTemplates.TemplateManager.RegisterTemplateOverrides(TitleFieldContext);
- }
- ExecuteOrDelayUntilScriptLoaded(_registerCompletedRiskTitleTemplate, 'clienttemplates.js');
- })();
Note, that in this case we are using ListTemplateType 1101 for the Risks list instead of the value 171 for the original Task list type (Tasks with Timeline and Hierarchy to be exact). We get this list template value using the BaseTemplate property of our Risks list.
To ensure that the script is loaded on all views that include the Title field, we should set the JSLink property of the field with InternalName “LinkTitle”.
Assuming you deployed your .js file to a path under the layout folder as /YourHive/js/strikeThroughClosedRisks.js, you can register your script using the following PowerShell code:
$web = Get-SPWeb http://YourProjServer/PWA/Proj1
$list = $web.Lists["Risks"]
$field = $list.Fields.GetFieldByInternalName("LinkTitle")
$field.JSLink = "~sitecollectionlayouts/YourHive/js/strikeThroughClosedRisks.js"
$field.Update()
Of course, this script affects only the web site of the project Proj1. If you would like to deploy it to all of your projects, you should iterate through the project web sites, but even better, you can prepare a project web site template based on this PWS in advance as described in my post last year, and use this template for your projects.
After successfully deploying our script, the text of the Title field of the closed risk is display using a strikethrough: