Start by adding an extra attribute to the entity you show in the grid. Before posting it on the page, sort the objects by ‘Function’ and loop over it and give the new attribute a color name. Change to a new color name when ‘Function’ differs from the previous ‘Function’.
Given that ‘Function’ has a limited number of different values (say no more than ten or so) you can make sure that you have a set of colors that are easy to differentiate. Basic colors will do, green, blue, purple, red, yellow etc.
Now, use the cellgridstyler on the new column, which you need not even show.
Hope it helps, good luck.