2

我已经为下面的列定义配置了 ag-grid

    {
        headerName: 'Model Level',
        field: 'ModelLevelTimeSeries.Id.Value',
        editable: false,
        cellRendererFramework: RenderEntityComponent,
        cellStyle: { textAlign: "center" },
        suppressSizeToFit: true,
    }

基本上来自后端的字段可以返回 null

"ModelLevelTimeSeries": {
        "Id": null
    }

或者

"ModelLevelTimeSeries": {
    "Id": {
        "Value": "dec70622-3ab3-4b47-a324-f69a14a53beb"
    }
}

当我编辑单元格值时,它会返回nullinparams.value方法agInit
我正在使用“ag-grid”:“^17.0.0”、“ag-grid-angular”:“^17.0.0”。

4

3 回答 3

1

您可以为您的coldefs使用值设置器

{
  headerName: 'Model Level',
  field: 'ModelLevelTimeSeries.Id.Value',
  editable: false,
  cellRendererFramework: RenderEntityComponent,
  cellStyle: { textAlign: "center" },
  suppressSizeToFit: true,

  valueSetter: function(params: any){
     if (params.oldValue !== params.newValue) {
         params.data[params.colDef.field] = (params.newValue) !== "" ? params.newValue.toUpperCase() : "";
         return true;
     } 
     else {
         return false;
     }
  }
}
于 2018-04-03T18:14:42.210 回答
0

只需在列定义中添加 cellRnderer 函数

cellRenderer: params => params.value ? params.value : ''

现在会是这样

   {
        headerName: 'Model Level',
        field: 'ModelLevelTimeSeries.Id.Value',
        editable: false,
        //add below line
        cellRenderer: params => params.value ? params.value : ''
        cellRendererFramework: RenderEntityComponent,
        cellStyle: { textAlign: "center" },
        suppressSizeToFit: true,
    }
于 2018-04-03T12:03:06.797 回答
0

根据我的经验,如果字段是.a.nested.key,则在 valueSetter 中使用 params.data[params.colDef.field] 将不起作用,因为 params.colDef.field 只返回一个类似“ModelLevelTimeSeries.Id.Value”的字符串

目前,我依靠 lodash 的 set() 在 valueSetter 中执行此操作:

import * as set from 'lodash/set'

changeDetectValueSetter (params) {
  if (params.oldValue !== params.newValue) {
    set(params.data, params.colDef.field, params.newValue) // had to use lodash set, because params.colDef.field is a string representation of a nested object key
    // params.data.instruction.billingrecord.invoice_number = params.newValue // could have done this, but it's fixed for that field.
    // params.data[params.colDef.field] = params.newValue // this does not work at all if the field is.a.nested.key
    return true
  } else {
    return false
  }
},
于 2019-05-08T18:26:02.243 回答