none
Get all the rows in a document libray based on the document name RRS feed

  • Question

  • Dear all,

    I have a document library with documents contains the documentname some abc.I want to get all the rows(items)which document name contains abc and i want to apply some style to those all items.I have used below jquery but its not working.Please help me.Thanks in advance.

    $Text = $("tr .ms-alternating:contains('abc')"); 
    $Text.parent().css("background-color", "#01DF3A");

    Regards,

    Praveen

    Tuesday, July 17, 2018 2:26 AM

Answers

  • Hi,

    We can use the code below to achieve it. Add the code below into script editor web part in the list view.

    <script type="text/javascript">
    SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function(){
       SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
         OnPostRender: function(ctx) {
           var rows = ctx.ListData.Row;
           for (var i=0;i<rows.length;i++)
           {
              var name = rows[i]["FileLeafRef"];
    		  if(name!=undefined){
    			var rowId = GenerateIIDForListItem(ctx, rows[i]);
    			  var row = document.getElementById(rowId); 
    			  if(name.indexOf("Meeting")!=-1){
    				row.style.backgroundColor = "yellow";
    			  }
    			  if(name.indexOf("Decision")!=-1){
    				row.style.backgroundColor = "lightblue";
    			  }
    		  }   
           }
         }
       }); 
    
    });
    </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.

    • Marked as answer by Praveenrangu Wednesday, July 18, 2018 3:42 AM
    Wednesday, July 18, 2018 3:06 AM
    Moderator

All replies

  • Hi Praveen,

    You can try something like below. Its working as shown in below screenshot. If you want to highlight whole row you can call two more times parent (.parent().parent()) in below code line.

    $(".ms-listviewtable > tbody > tr a:contains('jquery')").parent().css("background-color", "#01DF3A");

    Regards.

    Tuesday, July 17, 2018 3:43 AM
  • Thanks for your reply jaydeep.I applied your code but my list is grop by.I want to apply this to the items inside grouping..But its applied to header.Below is the screen shot.Please help.
    Tuesday, July 17, 2018 4:16 AM
  • Hi Praveen,

    I have tried this in grouped view. Its working fine for me.

    $(".ms-listviewtable > tbody > tr a:contains('Navigation')").parent().parent().parent().css("background-color", "#01DF3A");

    Regards.

    Tuesday, July 17, 2018 4:27 AM
  • thanks for your reply.I tried with normal list view its working fine but the grouped view its not working for me.
    Tuesday, July 17, 2018 5:24 AM
  • Hi jaydeep its working with the code as u suggested.But the last grouped item its not working please help.Below is the code and screen shot.

    <script type="text/javascript" src="</script">https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function()
    {
    ExpGroupRenderData();


    });
    function ExpGroupRenderData()
        {
       $(".ms-listviewtable  > tbody > tr a:contains('Meeting')").parent().parent().parent().css("background-color", "yellow");
      $(".ms-listviewtable  > tbody > tr a:contains('Decision')").parent().parent().parent().css("background-color", "lightblue");

        }

    </script>

    Thanks

    Tuesday, July 17, 2018 9:13 AM
  • Hi,

    We can use the code below to achieve it. Add the code below into script editor web part in the list view.

    <script type="text/javascript">
    SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function(){
       SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
         OnPostRender: function(ctx) {
           var rows = ctx.ListData.Row;
           for (var i=0;i<rows.length;i++)
           {
              var name = rows[i]["FileLeafRef"];
    		  if(name!=undefined){
    			var rowId = GenerateIIDForListItem(ctx, rows[i]);
    			  var row = document.getElementById(rowId); 
    			  if(name.indexOf("Meeting")!=-1){
    				row.style.backgroundColor = "yellow";
    			  }
    			  if(name.indexOf("Decision")!=-1){
    				row.style.backgroundColor = "lightblue";
    			  }
    		  }   
           }
         }
       }); 
    
    });
    </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.

    • Marked as answer by Praveenrangu Wednesday, July 18, 2018 3:42 AM
    Wednesday, July 18, 2018 3:06 AM
    Moderator