1

Below is the code i am using, it is not firing.

Field Name is--> Name(linked to item with edit menu)

 (function () {

        //   Initialize the variables for overrides objects
        var overrideCtx = {};
        overrideCtx.Templates = {};



        //  Use BaseViewID and ListTemplateType to narrow focus/scope on 
        //  which web parts on the page are affected
        //overrideCtx.BaseViewID = 3;
       // overrideCtx.ListTemplateType = 170;

        /*
         * Using the Fields override leaves the rest of the rendering intact, but 
         * allows control over one or more specific fields in the existing view
         */


        overrideCtx.Templates.Fields = {
            "Title": { "View" : getLinkLocation }
        };



        /*
         * Register the template overrides.
         */
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

    })();

    function getLinkLocation(ctx) {

    alert(ctx.CurrentItem.LinkLocation);

    alert("Before calling function");
        return '<a href=\"' + ctx.CurrentItem.LinkLocation + '\" target=\"_blank\">' + ctx.CurrentItem['LinkLocation.desc'] + '</a>';

    }
1

I tried it in my SPO and the modified code below works fine.

Here's your code and I modified the following codes

overrideCtx.Templates.Fields = {
        "LinkFilename": { "View" : getLinkLocation }
    };

and this line

return '<a href=\"' + ctx.displayFormUrl + '&ID=' + ctx.CurrentItem.ID + '\" target=\"_blank\">' + ctx.CurrentItem.FileLeafRef + '</a>';

Here's the full code

(function () {

    //   Initialize the variables for overrides objects
    var overrideCtx = {};
    overrideCtx.Templates = {};



    //  Use BaseViewID and ListTemplateType to narrow focus/scope on 
    //  which web parts on the page are affected
    //overrideCtx.BaseViewID = 3;
   // overrideCtx.ListTemplateType = 170;

    /*
     * Using the Fields override leaves the rest of the rendering intact, but 
     * allows control over one or more specific fields in the existing view
     */


    overrideCtx.Templates.Fields = {
        "LinkFilename": { "View" : getLinkLocation }
    };



    /*
     * Register the template overrides.
     */
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

})();

function getLinkLocation(ctx) {

alert(ctx.CurrentItem.FileRef);

alert("Before calling function");
    return '<a href=\"' + ctx.displayFormUrl + '&ID=' + ctx.CurrentItem.ID + '\" target=\"_blank\">' + ctx.CurrentItem.FileLeafRef + '</a>';

}
  • Hi Aevntus, What if the field name is 'Name(linked to item with edit menu)'.? – spStacker Aug 25 '16 at 18:06
  • 1
    Just use the internal name of the column. which is LinkFilename – Aventus Aug 26 '16 at 0:07

Your Answer

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

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