Skip to main content
2 of 2
grammar
Dylan Cristy
  • 12.8k
  • 3
  • 32
  • 72

ctx in CSR not return the title

I need to make the action of clicking on the title of a list item open the edit form, and not the view form. To do this I chose to use CSR.

I have the following code:

(function () {
    var statusFieldCtx = {};
  
    statusFieldCtx.Templates = {};
    statusFieldCtx.Templates.Fields = {
        "Title": {"View": DataFieldViewTemplate},
        
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtx);
})();

function DataFieldViewTemplate(ctx) {       
    var data = ctx.CurrentItem.Title;
    console.log(data);      
}

But I see nothing in the browser console. If I change the code, this works, but the title column does not exist.

Here is my edited code:

(function () {
    var statusFieldCtx = {};
  
    statusFieldCtx.Templates = {};
    statusFieldCtx.Templates.Fields = {
        "dt_x0020_proximo_x0020_contato": {"View": DataFieldViewTemplate},
        
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtx);
})();

function DataFieldViewTemplate(ctx) {       
    var data = ctx;
    console.log(data);      
}

My questions are: Is there any error in my code? Can I do what I want in a different way?

Diego Hillesheim
  • 1.2k
  • 3
  • 18
  • 26