1

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;

}
}
4

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);
}
  • 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 '14 at 20:09
0

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.

0

You can check this article link given:

Having multiple JSLink based webparts on the same page, overrides all the other templates in SP 2013.

It is by design that it will override any other webpart with js link.

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.