0
votes

I'm having problems connecting ag-grid data. I'm getting this error because there are no columns in the data I'm trying to show.

Json data available as follow

[{id=1,customerNo:10},{id=2,customerNo:11,customerName:"Skarakas"}]

Ag-Grid columns as follows:

[{
  headerName: "id",
  field: "id"
}, {
  headerName: "Customer No",
  field: "customerNo"
}, {
  headerName: "Customer Name",
  field: "customerName"
}]

CustomerName already comes in rows but sometimes not. Ag-Grid does not work for this reason. Can I fix the problem without changing the data?

I cannot understand that the error is caused by the ag grid. but json works when I remove the customer name field from the data enter image description here

1
What is the exact error shown? - abd995
I cannot understand that the error is caused by the ag grid, but json works when I remove the customer name field from the data. I add picture. - skarakas
@skarakas you can probably use valueGetter from Aggrid and if value that you are trying to access is undefined you can return default value in that case. ag-grid.com/javascript-grid-value-getters/#value-getter - Rikin

1 Answers

1
votes

Here's one example on how you may be able to tackle that issue:

[{
    headerName: "id",
    field: "id"
  },
  {
    headerName: "Customer No",
    field: "customerNo"
  },
  {
    headerName: "Customer Name",
    field: "customerName",
    valueGetter: function(params) {
      const value = params.node.data[params.colDef.headerName];
      return value === undefined ? '' : value;
    }
  }
]

There may be better and even easier way, probably by setting defaultValue but you have to dig up Aggrid's huge pile of documentation.