【问题标题】:customizeText devextreme not working自定义文本 devextreme 不起作用
【发布时间】:2017-03-28 10:58:40
【问题描述】:

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;
}

我正在尝试更改单元格中数据的字体颜色 如果数据大于或等于零文本将是绿色否则红色

【问题讨论】:

    标签: jquery devexpress devextreme


    【解决方案1】:

    customizeText 方法不接受 2 个参数。好吧,如果你打开浏览器控制台,你会看到 javascript 错误。

    在您的情况下,您可以使用cellTemplate 选项:

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

    Demo.

    【讨论】:

      【解决方案2】:

      参考这个 - dxDataGrid - customizeText does not change cell text under certain conditions

      customText 回调函数用于更改单元格 文本。如果您希望完全自定义单元格内容,请仅使用 cellTemplate.

      希望对您有所帮助..

      【讨论】:

        猜你喜欢
        • 2017-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-11
        • 1970-01-01
        • 1970-01-01
        • 2014-04-27
        相关资源
        最近更新 更多