0

I'm having issues adding a hyperlink to a field using the below. My column field is called LinkTitle (single Line of Text) My view is called Dashboard and i have refrenced the js like so ~sitecollection/SiteName/SiteAssets/jsLink.js But it doesn't work. Any ideas what i'm doing wrong or missing?

(function () {  

    // Create an object that have the context information about the fields that we want to change the rendering of.   

    var nameFiledContext = {};  

    nameFiledContext.Templates = {};  

    nameFiledContext.Templates.Fields = {  

        // Apply the new hyperlink HTML Rendering to the field in your view.  Swap out "<Your Field Name>" for your field name 

        "LinkTitle": { "View": DashBoard }  

    };  

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(nameFiledContext);  

})();  



// This function applies the rendering logic 

function DashBoard(ctx) {  

    var name = ctx.CurrentItem.LinkTitle;  //Swap out name variable for whatever field contains your hyperlink name



    return "<a target='_blank' href='http://google.com"   

        + name + "</a>";      //Put the url for your hyperlink in the href above

}  
3
  • 1
    Try your code in the way I mentioned in my answer at: sharepoint.stackexchange.com/questions/275592/…. Let me know if this works for you. Mar 16, 2020 at 7:10
  • Hi Ganesh, The sample you proposed only works for Title field i added Edit (link to edit item) But the links only appeared on the Title field. Also changed to a different column but no luck
    – naijacoder
    Mar 18, 2020 at 0:28
  • All good , It just took a while to replicate.
    – naijacoder
    Mar 19, 2020 at 6:47

2 Answers 2

1

I will suggest you to use the Client Side Rendering like below:

(function () {
    function registerRenderer() {
        var ctxForm = {};
        ctxForm.Templates = {};

        ctxForm.Templates = {
            Fields : {
                'LinkTitle': { //------ Change Hyperlink of LinkTitle
                    View : function (ctx) {
                        var url = String.format('{0}?ID={1}', "/sites/SiteName/Lists/ListName/EditForm.aspx", ctx.CurrentItem.ID);
                        return String.format('<a href="{0}" onclick="EditItem2(event, \'{0}\');return false;">{1}</a>', url, ctx.CurrentItem.Title);
                    }
                },
            }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
    }
    ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
})();

Here I have added the edit form link on Title (linked to item with edit menu) column whose internal name is LinkTitle. If you want to add it on another column then you need to add the internal name of your column instead of LinkTitle.

You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

How to set the JSLink property of your Web Part:

For detailed steps, check my answer given at: sharepoint 2013 list expand/collapse multiple line text column

0
0

Use the masterpage gallery or styles library location to store the jslink file and reference as below:

Sitecollection level: ~sitecollection/_catalogs/masterpage/<your js file>.js

Site level: ~site/_catalogs/masterpage/<your js file>.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.