How can I add an icon inside a brazos datatable

213 views Asked by At

I want to display an icon instead of a string or boolean inside a data table? Use case is as follows: the user wants to see an icon (e.g. a check or an x) depending on a value inside a business object. Anyone have any ideas?

1

There are 1 answers

0
Scott Francis On BEST ANSWER

Here's one approach:
Bind the value of the business object property to an output text that it’s inside the Data Table. In the configuration properties of the Output Text check the “Is HTML” option, then go to Advanced Options and put the name (say ‘getIconHTML’) of a java script function that will resolve and return the HTML of the icon. Then add a “Custom HTML” element to the Coach and a code similar to this:

<script>
function getIconHTML(action){
 var htmlAction = “”;
 if(!!action){
  switch(action){
   case “ADD” : htmlAction = ‘<font color=“green”><i class="fa fa-check” aria-hdden=“true”></i></font>’; break;
   case “REMOVE” : htmlAction = ‘<font color=“red”><i class="fa fa-times” aria-hdden=“true”></i></font>’; break;
   default : break;
  }
  return htmlAction;
 } else {
  htmlAction = “”;
  return htmlAction;
 }
}
</script>

Here we’re using font awesome icons, but could also use the decimal code of the HTML entities like &#10008 (for the x) or &#10004 for the checkmark.

Hope this helps!