Selective font styling in grid

2
I’m trying to change font color for rows in a grid selectively based on an “Enumeration” attribute. Say for an object, the value of that attribute is “YES”, then the font color in that row should be red.
asked
2 answers
1

Hi Dheerej,

 

I have used  “Grid Cell Styler” https://marketplace.mendix.com/link/component/106254 widget. 

You should be able to write logic in a nanoflow to change text color or also using a javascript. 

Best widget to change text color or row BG color in data grid.

You should be able to see demo here : https://cellstyler-sandbox.mxapps.io/

Hope this helps,

 

Ashok

answered
1

Hello DHEEREJ,

To achieve this you’ll use the Dynamic row class feature found in DataGrid2

 

First create a custom .scss file

  • Open Notepad on your PC and add custom classes like
.yes
{
    color: red;
}

.no
{
    color: black;
}
  • In the Save as window, change the Save as type to “All files”
  • Name the file “enum-styling.scss” (Could be any name but it should have .scss)
  • Save the file in your project directory > theme > web (You can get there through Mendix Studio Pro: In the top bar, click App > Show App Directory in Explorer)
  • In that same web folder right click on main.scss and Open with… Notepad then import your file like this
@import "custom-variables";
@import "enum-styling.scss";

 

Now in Mendix Studio Pro

  • Add a DataGrid2 and open its properties
  • Set the data source and columns
  • Then click on the Edit button next to the Dynamic row class
  • Your expression should look similar to this
if getCaption($currentObject/myEnumAttribute) = 'YES'
then 'yes'
else 'no'

*Replace “myEnumAttribute” with your enumeration attribute’s name

*Keep in mind that getCaption() retrieves the enumeration’s Caption and getKey() retrieves the enumeration’s Name

*Make sure you save and apply the changes

answered