Workflow and ServiceDesk Community

 View Only

Workflow - Grid View Column Cell Colouring 

Jul 15, 2015 03:46 PM

In this article I will show you how to change the colour of a cell (in a given column) in a Grid.png Grid Component in the Forms (Web).png Forms (Web) Project Type.

This can be handy for a RAG Status or Traffic light system.

 

Linked Article

https://www-secure.symantec.com/connect/articles/workflow-multistatecolor-component

 

Add a Grid.png Grid to your Form Builder.png Web Form.

Give the Grid a name

Functionality tab
Control ID: ProdTable

This assumes the data set you are returning includes a column that lists the colour you want to show.

Data Colour
John Red
Fred Amber
Lucy Green

Make this the LAST column of your Table.

You want it to change to

Table Colour.png

Add the following to the onload event of the Form.

Double click on the Form, go to the Behavior Tab.

In the 'Body Custom Events' click on Add -> AttributesKeyValuePair.

Event onload
Event Handler #below code#

 

$(function () {
    $('#ProdTable tr').each(function (index, value) {
        var lastTr = $('td', value).last();
        var colour = lastTr.text();
        if( colour == 'Amber' )
            colour = 'Orange';
            lastTr.text('');
            lastTr.css("background-color", colour);
    });
});

*There are certain colours in CSS instead of using the HEX code, Amber is not one of them so we need to change it to Orange.

https://css-tricks.com/snippets/css/named-colors-and-hex-equivalents/

There's an interesting read on why "ChuckNorris" is a colour.

 

If you wish to have it update a different column you will need to change the following line

var lastTr = $('td', value).last();

and get the column you need instead.

 

This works fine for the first page of a Grid but the Paging is performed using AJAX so if you change to Page 2 the colours aren't updated.

To combat this

$(function() {
    var previous = $("#ProdTable").text();
    $check = function() {
        if ($("#ProdTable").text() != previous) { 
          updateColor();
        }
        previous = $("#ProdTable").text();        
    }
    updateColor();
    setInterval(function() { $check(); }, 1000);
});

function updateColor() {
    $('#ProdTable tr').each(function (index, value) {
      var colour =  $(':nth-child(11)', $(this)).text();      
      var lastTr = $('td', value).last();   
    
      if( colour == 'Amber' )
          colour = 'Orange';
   
      lastTr.text('');
      lastTr.css("background-color", colour);
    });
}

This uses a Timer to keep checking the Grid so it's the best performance wise solution but it works.

 

In Workflow 7.5 you could just map a value into a Column of

<span style="background-color:blue"></span>
You could map across the colour from the DataType using the Merge component.
 
This is now encoded in the Grid in 7.6, the "<" is converted to "&lt;" etc so therefore doesn't work anymore.
 

Protirus.png

Statistics
0 Favorited
2 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Sep 04, 2017 03:17 AM

This Article shows you how:

Grid component customization, colours, images etc., Workflow 8.0+
https://www.symantec.com/connect/articles/grid-component-customization-colours-images-etc-workflow-80

Nov 04, 2016 06:03 AM

The code should work in 8 as it does in 7.6, have you tried it and got errors?

If you have the image path in your data type you could build up and image tag

<img src="smiley.gif" alt="Smiley face" height="42" width="42">

Just replace the values you need. Or don't add them at all.

Nov 04, 2016 05:44 AM

Hi Alex.

Do you know if there are any chance to get this to work in 8.0? Another question that I have is if you know of a way to add a image into a Grid cell?

BR /// Per-Erik

 

 

 

 

 

Oct 20, 2016 04:54 AM

Hi Per-Erik,

If you take a look at the "updateColor" it's selecting the "td" element, instead target the table row "tr" and then you'll change the whole row instead of just the cell.

Alex

Oct 20, 2016 03:28 AM

Hi Alex,

Do you know if there is any way to change the background color of a Grid component row based on e.g. text content in a specific cell in that row? I am looking for a way to do this in 8.0 but according to your last update the Grid seems to be encoded different from 7.6.

BR /// Per-Erik

 

 

 

Related Entries and Links

No Related Resource entered.