How to Color a Column

Hi all,

I have a grid that I would like to have a column with colors that are different depending on whether or not they contain a phrase which will start with (free or guaranteed or upgrade for example).

I understand that to color a column this code can be changed on the dhtmlxgridcell.js file around line 640:

if (val=="0")
  else if (val=="1")

but if i need it to find not an exact match for the word but see if the whole column contains the word what phrasing would I need to use?

Is it also possible to change the font color for the text in the column as well?

So the word “free” would have a cell that would have a red background with yellow text, the word “upgrade” would have a cell that would have a yellow background with red text, etc.?

Thanks any help would be most appreciated!



You can use “onRowCreated” to check value in each cell and change it’s style:

grid.attachEvent("onRowCreated", function(rId,rObj,rXml){\ if (grid.cellById(rId).getValue()="some match"){ grid.setRowTextStyle(rId,"background-color:red"); } });

Also you can create custom eXcell type. Please find tutorial here … l_creation

Hi Olga,

just a question, can this be used with the free version of DHTMLX or do i need the professional edition?

Thanks, I am still working it out - it gives me a blank white screen now and does not load the data. I am pretty green at this programming so it might take me a while to figure it out :slight_smile:


“onRowCreated” event is avaialble in PRO version only.
So the best way for you is to use custom eXcell type, you can do that in Standard version.

HI olga,

Any chance there is a whole sample file for me to grab the ~ Excell code for setBGColor from as I cannot figure it out for the life of me (and I have been trying but I am unsure what values need to go where and where the code would go exactly)?



Please check tutorial here … le_excells

Hi Olga,

We decided to test out the pro version because i think its something we will be using soon anyway!

So I am using “onRowCreated” and its working to color the column, BUT— how do i color the column by searching for a single word that is contained in the field and not the only word in there?

so if i have a row that contains the words: “Free upgrade” I want it colored. Right now its only finding columns that have the word “Free” in it alone? Many thanks :slight_smile:

I have attached the code below

grid.attachEvent("onRowCreated", function(Deals){
if (grid.cellById(Deals,0).getValue()="FREE"){



Basic column color works for me, disable resize doesn’t. Can even use #ccodes