# Display rules on a list view

**URL:** <https://forums.knack.com/t/display-rules-on-a-list-view/12161>\
**Category:** Show & Tell\
**Created:** [March 3, 2022, 7:31pm UTC](https://forums.knack.com/t/display-rules-on-a-list-view/12161 "2022-03-03T19:31:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harry](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/harry/32/1459_2.png) [@Harry](https://forums.knack.com/u/Harry)\
**Post date:** [March 3, 2022, 7:31pm UTC](https://forums.knack.com/t/display-rules-on-a-list-view/12161/1 "2022-03-03T19:31:57Z")

</div>

Hi all, I’ve written a small piece of code for adding display rules to (the first entry in) a list view. The ‘data[0]’ specifies that it’s the first entry. I’m sure with a small amount of tweaking (perhaps a loop) this could be adjusted to make changes to the whole view.

So in my case, I’ve retrieved the value for field\_yyy in the first record in the list and appended different classes (gold, silver or bronze) depending on the value of that field.

```auto
$(document).on('knack-view-render.view_xxx', function(event, view, data) {
  let savingsRate = parseFloat(data[0].field_yyy)
  const savingsRateHTML = document.querySelector(".field_yyy .kn-detail-body");
  if ( savingsRate > 50) {
    savingsRateHTML.className += " gold";
  } 
  else if (savingsRate > 30) {
    savingsRateHTML.className += " silver";
  }
  else if (savingsRate > 10) {
    savingsRateHTML.className += " bronze";
  }
  else {
    savingsRateHTML.className += " black";
  }
})

```

I then used CSS to define the colours of these entries in the list view.

```auto
.gold {
    color: #ffd700;
}
.silver {
    color: #c0c0c0;
}
.bronze {
    color: #cd7f32;
}

```

Which colours the value of the field as required 🙂

![Screenshot 2022-03-03 at 19.29.51](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/6/6c0e7c6a9a091c6d7f4769249f30e8d7ff4bbc87.png)

I’m new to coding so please let me know if there are any obvious improvements to how this can be done.

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 9, 2022, 12:57pm UTC](https://forums.knack.com/t/display-rules-on-a-list-view/12161/2 "2022-06-09T12:57:44Z")

</div>

Hi Harry, I have a use-case for that, but instead of checking a number it is a text (steps in a process).

How should I modify the code?

tks
