Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using JS Link to override some columns on a Sharepoint 2013 List view. I have a Page with multiple list on which some list are different Views of the same List and other are Views from another List. The issue is that I want to override the Title Column of List A but my code is rendering All Title Columns of all the list I have on the Page.

I want to update items from a single list.

I used this guide to learn and setup my JS Link override

This is my Code

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

//alert("Override call worked");
//  Use BaseViewID and ListTemplateType to narrow focus/scope on 
//  which web parts on the page are affected
//  overrideCtx.BaseViewID = 1;
//  overrideCtx.ListTemplateType = 100;

/*
 * 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 = {
    'LinkTitle':
    {
        'View' : CasoColor
    },
    'DiasActivo': { 
        'View' : ActiveDays 
    },

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

function CasoColor(ctx)
{

switch(ctx.CurrentItem.Estatus)
{
    case "Asignado":
        return '<a style="color:green;" href="' + ctx.HttpRoot +     '/Lists/Casos/DispForm.aspx?ID=' + ctx.CurrentItem.ID + '">' + ctx.CurrentItem.Title + '</a>';         
    break;
    case "En Proceso":
        return '<span style="color:#008080;">  ' + ctx.CurrentItem.Title + '</span>';
    break;
    case "Inspeccion Realizada":
        return '<span style="color:#0055aa;">  ' + ctx.CurrentItem.Title + '</span>';
    break;
    case "Pendiente":
        return '<span style="color:#aa5500;">  ' + ctx.CurrentItem.Title + '</span>';
    break;
    case "Resuelto":
        return '<span style="color:#bf0040;">  ' + ctx.CurrentItem.Title + '</span>';
    break;
    case "Cerrado":
        return '<span style="color:red;">  ' + ctx.CurrentItem.Title + '</span>';
    break;
    default:
        return ctx.CurrentItem.Title;

}
}
share|improve this question

2 Answers 2

In your script, in the actual function returning the markup (i.e. CasoColor), you can check the title of the list and return the default rendering:

if (ctx.ListTitle != "Title of List"){
    return RenderItemTemplate(ctx);
}
share|improve this answer
    
Another method would be to turn off csr in the webpart properties by checking the 'server render' box under miscellaneous. I was wondering if you know of a way to point 2 different templates at 2 different views of the same list on the same page. Would it essentially be the same thing but with ctx.ViewTitle != "title of view"? –  Dave Sep 16 at 20:09

From: http://msdn.microsoft.com/en-us/magazine/dn745867.aspx

Keep in mind that when you use multiple instances of a list view Web Part on the same page and apply JSLink to one of the instances, the layout of all other list view Web Parts changes also, because internally SharePoint uses common rendering logic. To avoid this problem, you need to make sure the BaseViewID value won’t conflict with existing ViewIDs, so change the BaseViewID property of the context before overriding, for example, ctx.BaseViewID = 1000.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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