none
Code for jslink to bold specific titles

    Question

  • I have a list view and I need to bold the titles for only specific title values

    For instance, I have a title that is "Update POAM" how can I make just this title in the view bold.

    Please make sure you answer is not just links to other post. I am really looking for and exact answer that shows how to code this correctly

    mercredi 13 juin 2018 15:12

Réponses

  • Hi,

    Modify the code as below.

    <script type="text/javascript">
    (function () {	 
        var overrideCtx = {};
        overrideCtx.Templates = {};
        overrideCtx.Templates.Fields = {
            'LinkTitle': { 'View': boldTitle }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
    })();
     
    function boldTitle(ctx) {
        var field=ctx.CurrentItem["Title"];
    	if(field.indexOf("Update POAM")!=-1||field.indexOf("Update RAR")!=-1){
    		return "<b>"+field+"</b>";
    	}else{
    		return field;
    	}	
    }
    </script>

    Best Regards,

    Dennis


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


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    vendredi 15 juin 2018 01:25
    Modérateur

Toutes les réponses

  • Hi,

    Add the code below into a script editor web part in the list view page to achieve it.

    <script src="//code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    	$("div[field='LinkTitle']").each(function(){
    		if($(this).text().indexOf("Update POAM")!=-1){
    			$(this).css("font-weight","bold");
    		}
    	});
    });
    </script>

    Or we can also use JSLINK to achieve it.

    <script type="text/javascript">
    (function () {	 
        var overrideCtx = {};
        overrideCtx.Templates = {};
        overrideCtx.Templates.Fields = {
            'LinkTitle': { 'View': boldTitle }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
    })();
     
    function boldTitle(ctx) {
        var field=ctx.CurrentItem["Title"];
    	if(field.indexOf("Update POAM")!=-1){
    		return "<b>"+field+"</b>";
    	}else{
    		return field;
    	}	
    }
    </script>
    

    Best Regards,

    Dennis


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


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


    jeudi 14 juin 2018 03:24
    Modérateur
  • Excellent answer.... Perfect result.

    What is there are to values that need to be Bold

    Update POAM and Update RAR.

    How you do the and || in the line of code?

    jeudi 14 juin 2018 13:58
  • Hi,

    Modify the code as below.

    <script type="text/javascript">
    (function () {	 
        var overrideCtx = {};
        overrideCtx.Templates = {};
        overrideCtx.Templates.Fields = {
            'LinkTitle': { 'View': boldTitle }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
    })();
     
    function boldTitle(ctx) {
        var field=ctx.CurrentItem["Title"];
    	if(field.indexOf("Update POAM")!=-1||field.indexOf("Update RAR")!=-1){
    		return "<b>"+field+"</b>";
    	}else{
    		return field;
    	}	
    }
    </script>

    Best Regards,

    Dennis


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


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    vendredi 15 juin 2018 01:25
    Modérateur