0

I use JSLink to color rows in a SharePoint 2013 list

ExecuteOrDelayUntilBodyLoaded(function () {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {

        RegisterModuleInit(_spPageContextInfo.siteServerRelativeUrl + "/SiteAssets/jsLink.js", Highlight); 
        Highlight();
    }
  });

});
function Highlight() {   

var HighlightFieldCtx = {};
HighlightFieldCtx.Templates = {};
HighlightFieldCtx.Templates.Fields = {};  

HighlightFieldCtx.OnPostRender =  postRenderHandler;     

 SPClientTemplates.TemplateManager.RegisterTemplateOverrides(HighlightFieldCtx);  
}


function postRenderHandler(ctx)
{

 var rows = ctx.ListData.Row;


 for (var i=0;i<rows.length;i++)
{
    // do stuff
    row.classList.add("Color");


}

}  

I need add SP.SOD.executeFunc() for activate _spPageContextInfo. But when I added SP.SOD.executeFunc(), function postRenderHandler not called in line with HighlightFieldCtx.OnPostRender = postRenderHandler. When I dont have SP.SOD.ExecuteFunc() and static link on my JS and CSS, my code and rendering fully working. Can you please help me, how to make proper code with working _spPageContextInfo?

Revolt
  • 89
  • 1
  • 9
  • Are you wanting to add color to only certain rows? Are you coloring every other row just to make it easier to see which row the data pertains to (color, no color, color, etc..)? – Matt Feb 27 '19 at 17:31

1 Answers1

0

Try this:

<script type="text/javascript">

            SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
                //alert(_spPageContextInfo.siteServerRelativeUrl);
                RegisterModuleInit(_spPageContextInfo.siteServerRelativeUrl + "/SiteAssets/jsLink.js", Highlight);
                Highlight();
            });

        function Highlight() {

            var HighlightFieldCtx = {};
            HighlightFieldCtx.Templates = {};
            HighlightFieldCtx.Templates.Fields = {};
            HighlightFieldCtx.OnPostRender =  postRenderHandler;
            SPClientTemplates.TemplateManager.RegisterTemplateOverrides(HighlightFieldCtx);
        }

        function postRenderHandler(ctx)
        {
            var rows = ctx.ListData.Row;
            alert('postRenderHandler');
        }
    </script>
Lee
  • 5,305
  • 1
  • 6
  • 12