Search code examples
jquerydevexpressdevextreme

customizeText devextreme not working


datagrid = $("#gridContainer").dxDataGrid({
  columns: [{
    dataField: "STCG",
    caption: "STCG",
    format: 'fixedPoint',
    allowFiltering: false,
    precision: 2,
    customizeText: function(cellElement, cellInfo) {
      var fieldData = cellInfo.value;

      if (fieldData >= 0) {
        cellInfo.cellElement.addClass("greencolortext");
      } else {
        cellInfo.cellElement.addClass("redcolortext");
      }
    }
  }]
}).dxDataGrid("instance");
.greencolortext {
  color: #2DC48D;
}

.redcolortext {
  color: #bf4e6a;
}

i am trying to change the font color of data in cell if data in greater than or equal to zero text will be green else red


Solution

  • The customizeText method doesn't take 2 arguments. Well if you open browser console you will see javascript errors.

    In your case you can use the cellTemplate option:

    cellTemplate: function($cell, cellInfo) {
        var fieldData = cellInfo.data.STCG;
        if (fieldData >= 0) {
            $cell.addClass("greencolortext");
        } else {
            $cell.addClass("redcolortext");
        }
    
        $cell.append(cellInfo.text);
    }
    

    Demo.