Datagrid2 has the dynamic classes as advantage. But since it does not have all the features of a datagrid, this might not work for you.
The solution for the original datagrid is the marketplace module “grid cell styler”. A bit of javascript and a nice jQuery-selector will make it possible for you to give any style to any condition. See https://mydemoversion8-sandbox.mxapps.io/p/appdemo/gridcellstyler for some examples and explanation.
Use datagrid 2 instead.
This is a new and better implementation of the datagrid and allows for element styling.
When using the datagrid 3, you can set dynamic classes in the appearance of the text widget
You can use data grid 2 or make your changes on the CSS files