28
Views
7
Comments
How to add Tag component in the Outsystems data grid column
Question

How to add Tag component in the Outsystems data grid column? I need to add tag in the classification column and the colour of tag is changing based on status. 

I need a guide for this.... because I'm first time using data grid... Thank you..

2025-12-04 09-01-03
Kiet Phan
Champion

@JWLoo 

Yes, you can archive that with javascript below:

  1. let myGrid = OutSystems.GridAPI.GridManager.GetGridById("MyGrid").provider;
  2. myGrid.formatItem.addHandler(function (s, e) {
  3.     if (e.panel === s.cells && s.columns[e.col].binding === "Sample_Product.Brand") {
  4.         const cellValue = s.getCellData(e.row, e.col, false);
  5.         const tag = document.createElement("span");
  6.         tag.className = "tag"; // Add a class for styling
  7.         tag.textContent = cellValue; // Set the tag text to the cell value
  8.         // Optionally, apply color based on value
  9.         if (cellValue === "Apple") {
  10.             tag.style.backgroundColor = "green";
  11.             tag.style.color = "white";
  12.         } else if (cellValue === "KFC") {
  13.             tag.style.backgroundColor = "orange";
  14.             tag.style.color = "white";
  15.         } else {
  16.             tag.style.backgroundColor = "gray";
  17.             tag.style.color = "white";
  18.         }
  19.         e.cell.textContent = ""; // Clear any existing text
  20.         e.cell.appendChild(tag); // Add the tag component
  21.     }
  22. });

The result:

2025-12-04 09-01-03
Kiet Phan
Champion

Hi @JWLoo,

If you feel my solution helped, please mark it The Solution for the question. It will help other users who have same problem find the answer faster.

UserImage.jpg
JWLoo

Hi @Kiet Phan, can you provide the oml on how to apply the javascript? Because it's not working in my screen. Thanks.


2024-12-10 04-40-04
Gitansh Anand

Hi @JWLoo, you can use "Tag" block available in "OutSystemsUI", it accepts pre defined colors from "color" static entity, in case you want custom colors, you can write your own CSS and use that using the "ExtendedClass" input.

Thanks
Gitansh Anand

UserImage.jpg
JWLoo

can this tag component use inside the data grid? if yes, please guide me on that. Thanks

2024-12-10 04-40-04
Gitansh Anand

Hi @JWLooyes it can be used in data grid, just put this block where you have placed your expression value of "Classification" column and move that expression value inside the "Tag" block. This block has color input which accepts Color Identifier, you can use "If" condition to set different colors based on different values of "Classification" column, there is also an input "IsLight", if you set it as true it will use lighter shades of the colors, and a I mentioned previously if you don't like the predefined colors you can write your own CSS and apply it with "ExtendedClass" input. Please refer to the attached OML.

Thanks
Gitansh Anand

Tag.oml
UserImage.jpg
JWLoo

Hi Gitansh Anand, thank you but the oml file that you sent is using table component, it's not using data grid component....and I can't put a block or tag components inside the data grid....


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.