Saturday, September 28, 2019

Using JSOM to make the Title column clickable on a SP list

I recently had a request to make the Title column of a SharePoint list clickable. You can simply use JSOM to override the template and render the Title column clickable. Don't forget to use "encodeURI" when returning the function in order to prevent issues with & ampersand in the URL.


(function () { 
    var overrideContext = {};
    overrideContext.Templates = {}; 
    overrideContext.Templates.Fields =
    {
        'Title': { 'View': overrideTemplate }
        
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext); 
})();

function overrideTemplate(ctx) {

    var title =    ctx.CurrentItem.Title;
    var name = ctx.CurrentItem["FileLeafRef"];
    var myLink = "https://URL.../" + name;

  
    return "<a id='myAnchor' href=" + encodeURI(myLink) + ">" 
        + title + "</a>";  

   
}

No comments:

Post a Comment

About Me

My photo
Toronto, Ontario, Canada
MBA, M.Sc. & MCP