I have a Javascript code that highlights my results on a specific status. The script works fine, but the problem when i search for an invoice id the color of the highlighted item disappear in search view.

So what should i add to the code to enable it in search view ?

This is my code:

    <script type="text/javascript">
  OnPostRender: function statusFieldContext(ctx) {
    var rows = ctx.ListData.Row;
    var color=  "#FFFFFF";
    for (var i=0;i<rows.length;i++)
      var isApproved = rows[i]["Status"] == "Approved";
      var isPending = rows[i]["Status"] == "Pending";
      var isRejected = rows[i]["Status"] == "Rejected";
      var isOpen = rows[i]["Status"] == "Open";
      if (isApproved)
        color = "#ada";
    else if (isPending){
     color = "DarkOrange";
      else if (isRejected){
          color = "#FF7474";
      else if (isOpen){
            color = "#AEF9F8";

      var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
      var tr = document.getElementById(rowElementId);
       if(tr != null){
        tr.style.backgroundColor = color;

Take a look on these 2 pictures: Before searching

After searching

Thank you !

  • Your code is working fine. did you enable the search box AFTER enabling search box? – harshal gite Sep 15 '19 at 18:12
  • I add the code using script editor. I did not add the file using JSLink because i am getting errors. "This XML file does not appear to have any style information associated with it. The document tree is shown below." Where should i enable the search box after enabling search box ? @harshal gite – SmithBZ Sep 16 '19 at 14:22
  • the style is not getting applied by this way. jslink will work for sure. remove script tag and save the code to file call it anything.js and upload it to site assets and then give a reference here as "~site/siteassets/anything.js" – harshal gite Sep 16 '19 at 14:50
  • I save the file in Site Assets,i save the file example.js and i remove the script tag but i am getting the same error: HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). GET - static.sharepointonline.com/bld/_layouts/15/16.0.19304.12019//… i call the file "/sites/mysite/SiteAssets/anything.js and no action was taken @harshal gite – SmithBZ Sep 17 '19 at 7:15
  • 1
    In jslink you should call the file as ~site/siteassets/example.js – harshal gite Sep 17 '19 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.