首页 > 解决方案 > 如果开发极端数据网格中的日期为空,则显示“-”

问题描述

我正在使用开发极端数据网格,如果日期不可用,我会显示为空白。如果日期为空,我想显示“-”。

我试过了

// component.html
[customizeText]="customizeMyText"

// component.ts
 customizeMyText(cellInfo: any) {
    console.log(cellInfo);
    if (cellInfo.value == '' || cellInfo.value == null || cellInfo.value == undefined) {
      return 'NA';
    } else {
      return cellInfo.value;
    }
 }

但它给出了一个错误, text.replace 不是一个函数。

标签: datagriddevexpressdevextreme-angular

解决方案


customizeText 函数的返回值需要一个字符串,请将您的函数更改为使用 valueText:

customizeMyText(cellInfo) {
if (
  cellInfo.value === "" ||
  cellInfo.value === null ||
  cellInfo.value === undefined
) {
  return "NA";
} else {
  return cellInfo.valueText;
}

};

来源:https ://js.devexpress.com/Documentation/ApiReference/UI_Widgets/dxDataGrid/Configuration/columns/#customizeText


推荐阅读