0

i had a scenario to bind nested and array of json to bind ag-grid using angular 5. i tried using valueGetter on my colDefs row data as Json to bind. nothing seems to be worked out. I see no examples with documentation as well.

Here is the json and code i had till now.

Json :

{
"packages": [
{
  "packageId": 2,
  "name": "Name1",
  "isEnabled": true,
  "packageRegistrationTypes": [
    {
      "registrationType": {
        "registrationTypeId": 1,
        "description": "Reg1"
      },
      "isActive": true
    },
    {
      "registrationType": {
        "registrationTypeId": 45,
        "description": "Reg2"
      },
      "isActive": false
    }
  ]
 }
 ]
}

Angular 5 :Coldef

  {headerName: 'Package Name',checkboxSelection: true,rowGroupIndex: 0, valueGetter: params => params.data.packages[0].name},

Row values i am binding from Service, but failed to get it. should i use any different format for binding nested values and array values.

2 Answers 2

1

I never tried to bend the ColDef, simply just change your data format a bit after you get your raw data.

Your data is key based instead of a regular array, I would do that

.subscribe(res => {
    this.data = Object.values(res.packages);
})
Sign up to request clarification or add additional context in comments.

3 Comments

This will make to loop for each record to get framed, hoping for better solution. like any in-builds in ag-grid handle these type of data
Take your post-processing data as your raw data for future usage, ex. ag-grid will never agree 100% with your server json.
Thanks mate, will go in this way
0

Basically exactly what @windmaomao said. When you call setRowData using the agGrid api pass data.packages as a parameter :- this.gridOptions.api.setRowData(data.packages); Following that field: 'name', should work when put inside the columnDefs (so I guess there would be no need for the valueGetter any more either)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.