# Dmn-js - how to highlight selected rules?

**URL:** <https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633>\
**Category:** Developers\
**Created:** [April 20, 2020, 10:39am UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633 "2020-04-20T10:39:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![VonDerBeck](https://forum.bpmn.io/user_avatar/forum.bpmn.io/vonderbeck/32/1927_2.png) [@VonDerBeck](https://forum.bpmn.io/u/VonDerBeck)\
**Post date:** [April 20, 2020, 10:39am UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633/1 "2020-04-20T10:39:49Z")

</div>

Hi folks,

there are already great examples on how to embed and use dmn-js within custom applications. See [https://github.com/bpmn-io/dmn-js-examples](https://github.com/bpmn-io/dmn-js-examples).

Similar to bpm-js, you can certainly access the individual components of the viewer to enhance the rendering according to your own needs.

Question: is there an easy way to access and highlight selected specific DMN rules / table rows in order to change the style, e.g. background, color, etc.?

Thanks in advance,  
Gunnar

---

<div class="post-metadata">

**Author:** ![mallesh](https://forum.bpmn.io/user_avatar/forum.bpmn.io/mallesh/32/1826_2.png) [@mallesh](https://forum.bpmn.io/u/mallesh)\
**Post date:** [April 20, 2020, 9:57pm UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633/2 "2020-04-20T21:57:10Z")

</div>

If it’s just CSS styles change, then I’m overriding the styles with my CSS. using developer tools, finding out the appropriate element styles and overriding the same. There could be elegant way, but for now this is how i’m overriding the look and feel of default styles

---

<div class="post-metadata">

**Author:** ![VonDerBeck](https://forum.bpmn.io/user_avatar/forum.bpmn.io/vonderbeck/32/1927_2.png) [@VonDerBeck](https://forum.bpmn.io/u/VonDerBeck)\
**Post date:** [April 21, 2020, 7:03am UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633/3 "2020-04-21T07:03:03Z")

</div>

What I’m looking for is a way to do something similar to BPMN Models in `dmn-js`, e.g. with markers:

**Sample from bpm-js** :

```auto
.highlight:not(.djs-connection) .djs-visual > :nth-child(1) {
  fill: green !important; /* color elements as green */
}

viewer.importXML(diagramXML, function() {
  var canvas = viewer.get('canvas');
  canvas.addMarker('UserTask_1', 'highlight');
});

```

Adding markers to individual selected rules this way would be cool. Of course there are workarounds by finding the corresponding elements within the DOM tree and adding css otherwise. It’s just that I’m looking for a more cleaner way.

---

<div class="post-metadata">

**Author:** ![Niklas\_Kiefer](https://forum.bpmn.io/user_avatar/forum.bpmn.io/niklas_kiefer/32/3882_2.png) [@Niklas\_Kiefer](https://forum.bpmn.io/u/Niklas_Kiefer)\
**Post date:** [April 21, 2020, 12:55pm UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633/4 "2020-04-21T12:55:35Z")

</div>

You have to know that the decision tables component is not built on `diagram-js`, but [`table-js`](https://github.com/bpmn-io/table-js), which do not have a Canvas module, and also not something like that, as far as I can see. So you won’t find an `addMarker` API for now, unfortunately.

But we’re open for contributions adding such a functionality 🚀

---

<div class="post-metadata">

**Author:** ![VonDerBeck](https://forum.bpmn.io/user_avatar/forum.bpmn.io/vonderbeck/32/1927_2.png) [@VonDerBeck](https://forum.bpmn.io/u/VonDerBeck)\
**Post date:** [April 22, 2020, 7:19am UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633/5 "2020-04-22T07:19:54Z")

</div>

Thanks @Niklas_Kiefer,

so i stick to the use of standard html DOM element methods.

For those of you interested how to accomplish this in [Vue.js](https://vuejs.org/) using something similar to [https://github.com/bpmn-io/vue-bpmn](https://github.com/bpmn-io/vue-bpmn) for DMN - here are some snippets:

**1.) Usage**

```auto
<template>
    ...
    <dmn-io
      :url="diagramXmlModelUrl"
      :highlightRuleNumbers="highlightRuleNumbers"
    />
    ...
</template>

<style>
  .dmn-highlight {
    background-color: #4caf507d !important
  }
</style>

<script>
  import VueDmn from '/../utils/vue-dmn-io'

  export default {
    components: {
      'dmn-io': VueDmn,
    },

    data () {
      return {
        diagramXmlModelUrl: null,
        highlightRuleNumbers: [],
       ...
      }
    },

   ...
   /* 
      Some code to 
      a) get the URL of your decision XML
      b) calculate the rule numbers to highlight (e.g. [2,4] )
   */
   ...

</script>

```

**2.) Implementation of vue-dmn-io.vue**

The important section for highlighting DMN table rows searches for the table body of the DMN table and then modifies the class of selected table rows. If someone of you has a better or more elegant solution - please let me know.

```auto
        if (self.highlightRuleNumbers) {
          var tbody = self.$refs.container.getElementsByTagName('tbody')[0]
          self.highlightRuleNumbers.forEach(ruleNo => tbody.childNodes[ruleNo - 1].setAttribute('class', 'dmn-highlight'))
        }

```

Full code - including migration of DMN 1.1:

```auto
<template>
  <div
    ref="container"
    class="vue-dmn-diagram-container"
  />
</template>

<script>
  import { migrateDiagram } from '@bpmn-io/dmn-migrate'
  import 'dmn-js/dist/assets/dmn-js-decision-table.css'
  import DmnJS from 'dmn-js/dist/dmn-viewer.production.min.js'

  export default {
    name: 'vue-dmn-io',
    props: {
      url: {
        type: String,
        required: true,
      },
      highlightRuleNumbers: {
        type: Array,
        required: false,
      },
    },
    data: function () {
      return {
        diagramXML: null,
      }
    },
    mounted: function () {
      var container = this.$refs.container
      var self = this
      this.dmnViewer = new DmnJS({
        container: container,
      })
      this.dmnViewer.on('import.done', function (event) {
        var error = event.error
        var warnings = event.warnings
        if (error) {
          self.$emit('error', error)
        } else {
          self.$emit('shown', warnings)
        }
        if (self.highlightRuleNumbers) {
          var tbody = self.$refs.container.getElementsByTagName('tbody')[0]
          self.highlightRuleNumbers.forEach(ruleNo => tbody.childNodes[ruleNo - 1].setAttribute('class', 'dmn-highlight'))
        }
      })
      if (this.url) {
        this.fetchDiagram(this.url)
      }
    },
    beforeDestroy: function () {
      this.dmnViewer.destroy()
    },
    watch: {
      url: function (val) {
        this.$emit('loading')
        this.fetchDiagram(this.url)
      },
      diagramXML: async function (xml) {
        xml = await migrateDiagram(xml)
        this.dmnViewer.importXML(xml)
      },
    },
    methods: {
      fetchDiagram: function (url) {
        var self = this
        fetch(url)
          .then(function (response) {
            return response.text()
          })
          .then(function (text) {
            self.diagramXML = text
          })
          .catch(function (err) {
            self.$emit('error', err)
          })
      },
    },
  }
</script>

<style>
  .vue-dmn-diagram-container {
    height: 100%;
    width: 100%;
  }
</style>

```

**3.) DMN 1.1 POC / Sample Result**

![grafik](https://forum.bpmn.io/uploads/default/original/2X/2/25c19ed7a644913aee515ccf5fce6ae434c11264.png)

Perhaps this will help others with similar needs to kick start their own solutions. 🚀

And many thanks to the authors of bpmn-io - this is really great stuff 🙂  
Gunnar

---

<div class="post-metadata">

**Author:** ![Niklas\_Kiefer](https://forum.bpmn.io/user_avatar/forum.bpmn.io/niklas_kiefer/32/3882_2.png) [@Niklas\_Kiefer](https://forum.bpmn.io/u/Niklas_Kiefer)\
**Post date:** [April 22, 2020, 7:25am UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633/6 "2020-04-22T07:25:57Z")

</div>

Thanks for sharing your solution!

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [July 22, 2025, 3:31pm UTC](https://forum.bpmn.io/t/dmn-js-how-to-highlight-selected-rules/4633/7 "2025-07-22T15:31:07Z")

</div>

Closed on July 22, 2025, 3:31pm UTC


