Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Ralph on Apr 22, 2009 08:32
open dhtmlx forum
Dynamic background colors for rows

Is it possible to set the background color based on the values in the rows first column?

For instance I've got rows of meetings where the first column is a date. If that date is within this month I'd like to color the corresponding row yellow, if the date is next month I want the corresponding row to be green and so on. I was wondering if I could tweak the code you did for my previous dynamic colored cell question?

Thanks
Answer posted by Support on Apr 23, 2009 05:21
Most simple solution - use onRowCreated event

grid.attachEvent("onRowCreated",function(id){
          if (some_check(grid.cells(id,0).getValue()))
              grid.setRowTextStyle(id,"background-color:yellow");
          else
              grid.setRowTextStyle(id,"background-color:green");
})

where some_check - your date checking function

By the way, if you are using non-default date format - client side date parsing and checking may be a pretty complicated, it would be much easier to do such operation on server side and provide extra flag through userdata or row attribute
Answer posted by Ralph on Apr 23, 2009 09:18
Thanks that did it! I like your server side suggestion.