I'm trying to change the font color of a row in a datagrid if a certain word is found in a datafield. Is there a simple, inline way to do this?
Thanks
I'm trying to change the font color of a row in a datagrid if a certain word is found in a datafield. Is there a simple, inline way to do this?
Thanks
While rekaszeru's approach is certainly valid, I think putting this logic in item renderer is more logical.
You can create custom item renderer and make
setStyle("color", "...")
there based on data. Just don't forget to clear color when word is not found, because renderer are reused and will contain old values if not overwritten.You can override your
DataGrid
's drawRowBackground method, and check whether it needs custom background or not.If so, pass the new background color to the
super
call of this method:where
someWord
is the word you are searching for, andyourCustomColor
is theuint
representing the new background color, eg:You can try using the following code.Couple of points to note:
1) Use this approach if you are displaying simple text in your datagrid(Well,you can do this for other type of renderes too,but then you will have to write similar piece of code in other renderers too).
2) In this approach,basically we are recreating the item renderers when we say 'Highlight'.So this can cause some performance degradation,I feel.If you are using simple item renderers,I dont think this will make much impact on the perfomance.
Main Application mxml
Contents of CustomItemRenderer.mxml(assumed to be in the same folder as the above mxml)
Hope that helps.In the meantime I will also look if you can achieve this in a more simple way.