Change Cell-color depending on his text


I need to set a different color if the value is higher than 50. I did like the documentation said but the color doesn’t change :frowning:

<?php $wonr = $_GET['wonr']; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <link href="../dhtmlx/Connector/dhtmlx.css" rel="stylesheet" type="text/css" charset="utf-8">
      <link href="../dhtmlx/Grid/codebase/skins/dhtmlxgrid_dhx_skyblue.css" rel="stylesheet" type="text/css">
      <script src="../dhtmlx/Grid/codebase/dhtmlxcommon.js"></script>
      <script src="../dhtmlx/Grid/codebase/dhtmlxgrid.js"></script>        
      <script src="../dhtmlx/Grid/codebase/dhtmlxgridcell.js"></script>      
      <script src="../dhtmlx/Connector/dhtmlx.js" type="text/javascript" charset="utf-8"></script>
      <script src="../dhtmlx/Connector/dhtmlxdataprocessor.js" type="text/javascript" charset="utf-8"></script>
      <script src="../dhtmlx/Connector/connector.js" type="text/javascript" charset="utf-8"></script>

      <div id="gridbox" width="338px" height="103px" style="background-color:white;overflow:hidden"></div>

	     myGrid = new dhtmlXGridObject('gridbox');
	     myGrid.setHeader("Name, Strasse, TX, RX, SN");
	     myGrid.attachEvent("onXLE", function(){
			 rows = myGrid.getRowsNum();
			 for (var i = rows -1; i >= 0; i--) {
				 txt = myGrid.cells2(i, 2).getValue().toString().toLowerCase();
				 if(txt >= 50) { myGrid.setRowColor(i, "F46899"); }
	     myGrid.loadXML("../../php/connector.php?wonr=<?php echo $wonr; ?>");

Is there a way to change just the specified column? Where’s my mistake?

Thank you in advance.

Best regards

setRowColor() method uses row_id but not the row_index.
Please, try to modify your code the following way:

    if(txt >= 50) { myGrid.setRowColor(myGrid.getRowId(i), "F46899"); }

Thank you … as i just need to change the font color i tried:

if(txt >= 50) { myGrid.setRowTextStyle(myGrid.getRowId(i), "color:red"); }

It works well but how can i use this code for a specified column?
For example: I want that only column 3 gets the new color.

Thank you :slight_smile:


if(txt >= 50) { myGrid.setCellTextStyle(myGrid.getRowId(i), 2, "color:red"); }

and works really well :slight_smile:

Thank you