簡體   English   中英

ag-grid object 嵌套數組

[英]ag-grid object nested array

大家好,我有數組作為列數據之一,我想使用 ag-grid 顯示它我可以知道我的選擇是什么

https://stackblitz.com/github/snehalp29/ag-grid-demo

columnDefs = [
    { field: 'freLoanId' , checkboxSelection: true,  headerCheckboxSelection: true},
    { field: 'loanAmt' },
    { field: 'interestRate'},
    {field: 'loanInterestRateStructureType'},
    {field: 'loanSecuritizationEligibilityInd'},
    {field: 'properties.pptyName'}
  ];

我嘗試了上面的代碼,但它不起作用

您可以執行以下操作:

columnDefs = [
    {
      field: "freLoanId",
      checkboxSelection: true,
      headerCheckboxSelection: true
    },
    { field: "loanAmt" },
    { field: "interestRate" },
    { field: "loanInterestRateStructureType" },
    { field: "loanSecuritizationEligibilityInd" },
    {
      field: "pptyName (or custom name)",
      valueGetter: params => {
        console.log(params.data.properties[0].pptyName);
        return params.data.properties[0].pptyName;
      }
    }
  ];

檢查: https://stackblitz.com/edit/github-a9uxcv?file=src/app/app.component.ts文檔:https://www.ag-grid.com/documentation/javascript/value-setters/

您不能在列定義field屬性中包含嵌套字段,因為這是 agGrid 內部使用的屬性,並且與您在rowData中傳遞的行 object 無關。

執行此操作的方法是使用cellRenderervalueGetter方法,同時為您的field屬性提供正確的名稱。

所以而不是:

{field: 'properties.pptyName'}

嘗試

{
  field: 'pptyName',
  valueGetter: (params) => {
    return params.value.properties.pptyName;
  }
}

如果您將整個properties object 傳遞給rowData屬性pptyName ,這將起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM