代码之家  ›  专栏  ›  技术社区  ›  Sandeep Kumar Troy Daniel

值求值后,ag grid cellRenderer无法呈现单元格

  •  1
  • Sandeep Kumar Troy Daniel  · 技术社区  · 6 年前

    我有一个内联cellRenderer来修改单元格内的值,如下所示:

    cellRenderer: function (params) {
      if(params.value) {
        return params.value * 100;
      }
      return '';
    }
    

    我在调试视图中观察到它正在正确计算该值。请找到截图 enter image description here

    但是,当控件移出cellRenderer时,会引发以下异常:

    ERROR TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
    at CellComp.push../node_modules/ag-grid/dist/lib/rendering/cellComp.js.CellComp.afterCellRendererCreated (cellComp.js:582)
    at Promise.push../node_modules/ag-grid/dist/lib/utils.js.Promise.then (utils.js:1543)
    at CellComp.push../node_modules/ag-grid/dist/lib/rendering/cellComp.js.CellComp.createCellRendererInstance (cellComp.js:564)
    at CellComp.push../node_modules/ag-grid/dist/lib/rendering/cellComp.js.CellComp.attachCellRenderer (cellComp.js:589)
    at CellComp.push../node_modules/ag-grid/dist/lib/rendering/cellComp.js.CellComp.afterAttached (cellComp.js:100)
    at rowComp.js:938
    at Array.forEach (<anonymous>)
    at RowComp.push../node_modules/ag-grid/dist/lib/rendering/rowComp.js.RowComp.callAfterRowAttachedOnCells (rowComp.js:936)
    at RowComp.push../node_modules/ag-grid/dist/lib/rendering/rowComp.js.RowComp.insertCellsIntoContainer (rowComp.js:554)
    at RowComp.push../node_modules/ag-grid/dist/lib/rendering/rowComp.js.RowComp.refreshCellsInAnimationFrame (rowComp.js:460)
    

    cellRenderer: function (params) {
      return params.context.formatDate(params.data.createdDateTime);
    }
    

    我在用 "ag-grid-enterprise": "^16.0.0", 角度6。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Paritosh    6 年前

    根据@Sh.Pavel的评论,它在更新到 return ''+ params.value * 100 .

    重要的是要明白, cellRenderer 期望 string

    因为你回来的是 number ,正确的 Node 我想是没有产生。这是通过做 return '' + params.value * 100;