none
jslink issues with multiple list views RRS feed

  • Question

  • Hello Techies,

    I am stuck with jslink issues.

    I have a list with various columns say BRDDate, KickOFFDate and Status.
    Note: There are other date columns for the list.

    Status column has options :

    BRD Received
    Kicked Off
    In discussion

    I need to create a KPI sort of multiple list views on a single page.

    I created one list view say BRD and based on that change the KPI images
    Here is the code:
    For this list view i applied filter for Status equals BRD Received and In discussion

    (function() {
        
    	var statusFieldCtxBRD= {};
    	statusFieldCtxBRD.Templates = {};
    	statusFieldCtxBRD.BaseViewID = 1;
      	statusFieldCtxBRD.ListTemplateType = 100;
      	statusFieldCtxBRD.ViewId='B0D1020C-CDFB-4F76-8A1A-8AF8F2283746';
    
    
    	statusFieldCtxBRD.Templates.Fields = {"KPI": {"View":StatusIconViewTemplateBRD}};
    
    
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtxBRD);
    
    })();
    
    function StatusIconViewTemplateBRD(ctx) {
    //debugger;
    	var _statusValue = ctx.CurrentItem["Status"];
    	var brdreceivedDate=ctx.CurrentItem["BRD_x0020_Received"];
    	//var_dueDate = new Date(ctx.CurrentItem.DueDate);
    	//alert("BRD: "+brdreceivedDate);
    	alert('BRD script');
    	var now = new Date();
    	now=(now.getDate() + '-' +now.getMonth() + 1) + '-' +  now.getFullYear();
    
    	//alert("HELLO");
    	if(ctx.wpq=='WPQ3')
    	{
    	
    			if(brdreceivedDate =='')
    			{
    				return '';
    		
    			}
    			else if(brdreceivedDate==now || brdreceivedDate<now)
    			{
    				return "<img width='40' height='40' src='/imisscpl/dw/SiteAssets/green.png'";
    			}
    			else
    			{
    				return "<img width='40' height='40' src='/imisscpl/dw/SiteAssets/red.png'";
    			}
    	}
    }
    


    Here is the issue, I created another list view for kickOff date and here is the jslink code:
    For this list view i applied filter for Status equals Kicked Off

    (function() {
        
    	var statusFieldKickOffCtx = {};
    	statusFieldKickOffCtx.Templates = {};
    	statusFieldKickOffCtx.BaseViewID =1;
      	statusFieldKickOffCtx.ListTemplateType = 100;
      	statusFieldKickOffCtx.ViewId='b058c8e2-07eb-4c1c-842e-8ecc8f24ac0c';
    
    	statusFieldKickOffCtx.Templates.Fields = {"KPI": {"View":StatusIconViewTemplatekickOff}};
    	
    	SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldKickOffCtx);
    
    })();
    
    function StatusIconViewTemplatekickOff(ctx) 
    	{
    		//debugger;
    		alert('kickOff script');
    		var _statusValue = ctx.CurrentItem["Status"];
    		var kickOffDate = ctx.CurrentItem["KickOff"];
    		//var_dueDate = new Date(ctx.CurrentItem.DueDate);
    		//alert("BRD: "+kickOffDate);
    	
    		var now = new Date();
    		now=(now.getDate() + '-' +now.getMonth() + 1) + '-' +  now.getFullYear();
    		if(ctx.wpq=='WPQ4')
    		{
    			if(kickOffDate=='')
    			{
    				return '';
    			}
    			else if(kickOffDate==now || kickOffDate < now)
    			{
    				return "<img width='40' height='40' src='/imisscpl/dw/SiteAssets/green.png'";
    			}
    			else
    			{
    				return "<img width='40' height='40' src='/imisscpl/dw/SiteAssets/red.png'";
    			}
    		}
    	}
    
    
    
    
    
    

    Jslink for a single list view is working fine but it not working for multiple list views.

    I tried giving list viewIDs and ctx.wpq in the jslink code but nothing works here.

    Please let me know where i am going wrong

    Wednesday, January 25, 2017 11:18 AM

Answers

  • Hi,

     

    If you want to limit to specific view, I think you could use ctx.view property.

    You could check below screenshot.

     

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Sachchin Thursday, February 2, 2017 11:15 AM
    Tuesday, January 31, 2017 4:21 AM

All replies

  • Hi,

     

    If you want to limit to specific view, I think you could use ctx.view property.

    You could check below screenshot.

     

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Sachchin Thursday, February 2, 2017 11:15 AM
    Tuesday, January 31, 2017 4:21 AM
  • Hello Lee,

    Thanks for your response i used another approach like this:

    if(ctx.wpq=='WPQ9')
    {

    }

    if(ctx.wpq=='WPQ3')
    {

    }

    It worked and also tried your approach which worked. 

    Thursday, February 2, 2017 11:15 AM