ng-matero / extensions

Angular Material Extensions Library.
https://ng-matero.github.io/extensions/
MIT License
393 stars 48 forks source link

Problem showing nested array of objects in mtx-table #120

Closed Aleks4ndarS closed 1 year ago

Aleks4ndarS commented 1 year ago

Hi I'm having problem displaying nested array of objects in the mtx-table,

This is my data:

{
    "owner": {
        "date": "2016-12-20T15:02:46.00+01:00",
        "action": "DELETE",
        "value": "admin"
    },
    "registered": "false",
    "description": "Dummy description",
    "type": {
        "details": "LOW",
        "id": "x7"
    },
    "number":
     [
        {
            "type": "Dummy type",
            "value": [
                "231454452",
                "4334523"
            ],
            "order": "16"
        }
      ], 
    "name": "Dummy data",
    "id": "34456567",
    "references": {
        "reference": [
            {
                "id": "DUMMY_REF_ID",
                "type": "dummy type"
            }
        ]
    },
    "status": {
        "dateCreated": "2016-12-20T15:02:47.00+01:00"
    }
}

this is my mtxColumn:

columns: MtxGridColumn[] = [
    { header: 'Action', field: 'owner.action', sortable: true },
    { header: 'Name', field: 'name', sortable: true },
    { header: 'Type', field: "number[0]['type']", sortable: true },
    { header: 'Date', field: 'status.dateCreated', sortable: true, }]

I'm having issue with the display of the Type field: "number[0].['type']". Since I didn't come to a similar problem anywhere, can someone describe me how to display this. Also it would be helpful for the references reference.id to share some ideas.

Thanks in advance.

nzbin commented 1 year ago

Please try number.0.type and references.reference.0.id

Aleks4ndarS commented 1 year ago

Please try number.0.type and references.reference.0.id

Thanks for your quick answer. Sorry I forgot to write that I've tried that, also tried various syntaxes and nothing seems to read the data.

Aleks4ndarS commented 1 year ago

@nzbin Also another thing that I've noticed is that if the element is nested for example owner.action in that case the sorting of the column is not working, so the element must be on first level. Can u share your thoughts on this one too? Thanks.

About the first problem this would be a good solution in case someone needs it:

const transformed = response.map(el => {
          el['number'] = el['number'][0];
          return el;
        });
nzbin commented 1 year ago

It's very difficult to sort nested array. Maybe you can flat the array if you need sort.

Aleks4ndarS commented 1 year ago

Thank you for your answer. P.S. I didn't have the time to write that you are doing great job with the theme. Keep up the good work!