【问题标题】:How do I format number in cellTemplate using jquery Devextreme?如何使用 jquery Devextreme 在 cellTemplate 中格式化数字?
【发布时间】:2021-12-21 05:03:51
【问题描述】:

我想自定义我的借方和贷方列。有金额时会变成blue color,点击后会变成show pop up。如果是amount is zero,那么它将是blank。问题是当我使用 cellTemplate 自定义单元格时,customText 和格式不起作用。有人对此有想法吗?请看我的JS Fiddle

首先通过使用它,我可以使零值变为空白(参见借方列)

{
  dataField: "debit",
  caption: "DEBIT",
  dataType: "number",
  width: 150,
  format: "#,##0.00;(#,##0.00)",
  customizeText: function(cellInfo) {
    if (cellInfo.valueText === "0.00") {
      return " ";
    } else {
      return cellInfo.valueText;
    }
  },
}

添加 cellTemplate 后,customText 和格式不起作用。金额格式不正确,零也没有变成空白。 (见学分栏)

{
dataField: "credit",
  caption: "CREDIT",
  dataType: "number",
  width: 150,
  format: "#,##0.00;(#,##0.00)",
  customizeText: function(cellInfo) {
    if (cellInfo.valueText === "0.00") {
      return " ";
    } else {
      return cellInfo.valueText;
    }
  },
  cellTemplate: function(container, cellInfo) {
    var credit = cellInfo.data.credit;

    if (credit !== "0.0000") {
      var color1 = "blue"
    }
    $('<a/>').addClass('dx-link')
      .text(cellInfo.data.credit)
      .css("color", color1)
      .on('dxclick', function() {
       $("#popup").dxPopup("instance").show();
$("#txt").dxTextArea("instance").option("value", cellInfo.data.credit);
      })
      .appendTo(container);
  }
}

我当前的输出

【问题讨论】:

    标签: devextreme


    【解决方案1】:

    当您使用 cellTemplate 时,formatcustomizeText 将被忽略。使用 cellTemplate 时,您必须手动格式化值。

    【讨论】:

      猜你喜欢
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多