0

struggling with getting percentage complete bar graph working with 2019, was working great with JS file on 2013, but will not work with 2019,, attached screenshot for what we had with 2013 vs 2019

i apprecitate any help, maybe its just not possible in 2019

enter image description here

JS File below;

(function () {
    var condFieldCtx = {};

    // Define template variable  
    condFieldCtx.Templates = {};

    // Define your required fields and functions to call in each case.
    // In our case the field is Progress
    // Override Function is PatientProgressViewTemplate
    condFieldCtx.Templates.Fields = {
        "Priority": {"View": PriorityFormat},
        "PercentComplete": {"View": PercentCompleteFormat},
        "CreateDate": {"View": CreateDateFormat}      
    };
    
    //conditional formatting for a complete row comes here
    condFieldCtx.OnPostRender = [HighlightRowOverride];
    
    // Register the template override with SP2013 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(condFieldCtx);

})();

function CreateDateFormat(ctx)
{
    //Convert the CreateDate into a number with getTime()
    //ATTENTION: We Split by using '/' if you turn to another language setting it might not working!
    var CreateDate = new Date(ctx.CurrentItem.CreateDate.split('/')[2],ctx.CurrentItem.CreateDate.split('/')[0]-1,ctx.CurrentItem.CreateDate.split('/')[1]).getTime();
    
    var today = new Date();
    today.setHours(0,0,0,0);
    
    var todayNo = today.getTime();

    //Compare and react
    if(CreateDate == 'undefined' || !CreateDate)
    {
        return ctx.CurrentItem.CreateDate;
    }
    else if(CreateDate < todayNo)
    {
        return "<span><font style='background-color:red;display:block;'>"+ctx.CurrentItem.CreateDate+"</font></span>";

    }
    else if(CreateDate == todayNo)
    {
        return "<span><font style='background-color:yellow;display:block;'>"+ctx.CurrentItem.CreateDate+"</font></span>";       
    }
    else
    {
        return ctx.CurrentItem.CreateDate;
    }
}

function PriorityFormat(ctx)
{
    var priorityValue = ctx.CurrentItem.Priority;
    
    if(priorityValue == 'High')
    {
        return "<span><font style='background-color:red;display:block;'>"+ctx.CurrentItem.Priority+"</font></span>";
    }
    else
    {
        return ctx.CurrentItem.Priority;
    }
    
}

function PercentCompleteFormat(ctx)
{
    var returnvalue = '<div style="background: #BCBCBC; display:block; height: 20px; width: 100px;"><span style="color: #fff; position:absolute; text-align: center; width: 100px;">'+ctx.CurrentItem.PercentComplete+'</span><div style="background: #D2421F; height: 100%; width: '+ctx.CurrentItem.PercentComplete.replace(" %", "")+'%"></div></div>';
    return returnvalue;
    
}

function HighlightRowOverride (ctx)
{
    for(var i=0; i < ctx.ListData.Row.length; i++)
    {
        var listItem = ctx.ListData.Row[i];
        var iid = GenerateIIDForListItem(ctx, listItem);
        var row = document.getElementById(iid);
        
        if(listItem.Marked == "Yes")
        {
            row.style.backgroundColor = "rgba(4,92,8,0.1)";
        }
    }
    ctx.skipNextAnimation = true;
}
5
  • You could share the js code to track down this issue. Sep 9, 2021 at 0:44
  • Hello Michael, thanks in advance, added script to the main question
    – marco
    Sep 9, 2021 at 18:32
  • JSLink is not supported in modern UI. Have you tested with "classic" UI?
    – Mark L
    Sep 10, 2021 at 1:30
  • I tested JSLink still work in SP2019 classic UI
    – Mark L
    Sep 10, 2021 at 9:42
  • thanks Mark, did you have to make any changes to the code? i am using 2019 in classic UI,
    – marco
    Sep 10, 2021 at 15:26

0

Your Answer

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

Browse other questions tagged or ask your own question.