0

Based on this link in SharePoint2016 i tried to color a list. I failed.

First everything was green. Then yellow. Now no longer work at all now no matter what i do (even using previous script).

What am i doing wrong? Please help. Thanks.

Here is the code:

function colorCodeRows() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
    OnPostRender: function (ctx) {
        // get today's date
        var today = new Date();
        // zero out the time portion so we will only compare days
        today.setHours(0,0,0,0);

        var rows = ctx.ListData.Row;
        for (var i = 0; i < rows.length; i++) {

            // get the date set in your date YourDateField
            var itemDate = new Date(rows[i]["Határidő"]);
            // zero out the time portion so we only compare days
            itemDate.setHours(0,0,0,0);

            var rowId = GenerateIIDForListItem(ctx, rows[i]);
            var row = document.getElementById(rowId);

            if (itemDate > today) {
                row.style.backgroundColor = '#00FF00';
            } else if (itemDate == today) {
        row.style.backgroundColor = '#FFFF00';
    } else if (itemDate < today) {
        row.style.backgroundColor = '#FF0000';
    }
        }
    }
});

} RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens('~site/SiteAssets/JSLink/coloring.js'), colorCodeRows); colorCodeRows();

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.