CustomCodes‎ > ‎

JS Links for modifying views in SP 2013

(function () {
    // Intialize the variables for overrides objects
    var overrideCtx = {};
    overrideCtx.Templates = {};
 
    // Override field data
    overrideCtx.Templates.Fields = {
        // YOUR_FIELD = internal name of the field
        // View = you want to change the field rendering of a view
        // <div ... = here we define what the output of the field will be.
        'YOUR_FIELD': { 'View': EditSubmission }
    };
 
    // Register the override of the field
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
 
function EditSubmission(ctx) {
    //Logic comes here.. which creates an optput which is to be returned. 
    var returnValue;
    returnValue = "<a title='" + ctx.CurrentItem.Title + "'href='"+ _spPageContextInfo.webAbsoluteUrl + "/List/AllItems.aspx?ID=" + ctx.CurrentItem.ID + "'>" + ctx.CurrentItem.Title + "</a>";
    return returnValue;
    // return value can be some HTML snippet as: 
    // "<div style='text-align:center;'><img src='" + _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/Images/High.png' /></div>"
}
 
 
//NOTE: Deploy JS file to layout folder, and refer in JS link option in miscellaneous option in webpart properties of a list view.